
obj/user/primes:     file format elf32-i386


Disassembly of section .text:

00800020 <_start>:
// starts us running when we are initially loaded into a new environment.
.text
.globl _start
_start:
	// See if we were started with arguments on the stack
	cmpl $USTACKTOP, %esp
  800020:	81 fc 00 e0 bf ee    	cmp    $0xeebfe000,%esp
	jne args_exist
  800026:	75 04                	jne    80002c <args_exist>

	// If not, push dummy argc/argv arguments.
	// This happens when we are loaded by the kernel,
	// because the kernel does not know about passing arguments.
	pushl $0
  800028:	6a 00                	push   $0x0
	pushl $0
  80002a:	6a 00                	push   $0x0

0080002c <args_exist>:

args_exist:
	call libmain
  80002c:	e8 13 01 00 00       	call   800144 <libmain>
1:	jmp 1b
  800031:	eb fe                	jmp    800031 <args_exist+0x5>
	...

00800034 <primeproc>:

#include <inc/lib.h>

unsigned
primeproc(void)
{
  800034:	55                   	push   %ebp
  800035:	89 e5                	mov    %esp,%ebp
  800037:	57                   	push   %edi
  800038:	56                   	push   %esi
  800039:	53                   	push   %ebx
  80003a:	83 ec 2c             	sub    $0x2c,%esp
	int i, id, p;
	envid_t envid;

	// fetch a prime from our left neighbor
top:
	p = ipc_recv(&envid, 0, 0);
  80003d:	8d 75 e4             	lea    -0x1c(%ebp),%esi
  800040:	c7 44 24 08 00 00 00 	movl   $0x0,0x8(%esp)
  800047:	00 
  800048:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
  80004f:	00 
  800050:	89 34 24             	mov    %esi,(%esp)
  800053:	e8 ea 15 00 00       	call   801642 <ipc_recv>
  800058:	89 c3                	mov    %eax,%ebx
	cprintf("%d ", p);
  80005a:	89 44 24 04          	mov    %eax,0x4(%esp)
  80005e:	c7 04 24 80 2d 80 00 	movl   $0x802d80,(%esp)
  800065:	e8 0b 02 00 00       	call   800275 <cprintf>

	// fork a right neighbor to continue the chain
	if ((id = fork()) < 0)
  80006a:	e8 83 11 00 00       	call   8011f2 <fork>
  80006f:	89 c7                	mov    %eax,%edi
  800071:	85 c0                	test   %eax,%eax
  800073:	79 20                	jns    800095 <primeproc+0x61>
		panic("fork: %e", id);
  800075:	89 44 24 0c          	mov    %eax,0xc(%esp)
  800079:	c7 44 24 08 84 2d 80 	movl   $0x802d84,0x8(%esp)
  800080:	00 
  800081:	c7 44 24 04 1a 00 00 	movl   $0x1a,0x4(%esp)
  800088:	00 
  800089:	c7 04 24 8d 2d 80 00 	movl   $0x802d8d,(%esp)
  800090:	e8 1b 01 00 00       	call   8001b0 <_panic>
	if (id == 0)
  800095:	85 c0                	test   %eax,%eax
  800097:	74 a7                	je     800040 <primeproc+0xc>
		goto top;
	
	// filter out multiples of our prime
	while (1) {
		i = ipc_recv(&envid, 0, 0);
  800099:	8d 75 e4             	lea    -0x1c(%ebp),%esi
  80009c:	c7 44 24 08 00 00 00 	movl   $0x0,0x8(%esp)
  8000a3:	00 
  8000a4:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
  8000ab:	00 
  8000ac:	89 34 24             	mov    %esi,(%esp)
  8000af:	e8 8e 15 00 00       	call   801642 <ipc_recv>
  8000b4:	89 c1                	mov    %eax,%ecx
		if (i % p)
  8000b6:	89 c2                	mov    %eax,%edx
  8000b8:	c1 fa 1f             	sar    $0x1f,%edx
  8000bb:	f7 fb                	idiv   %ebx
  8000bd:	85 d2                	test   %edx,%edx
  8000bf:	74 db                	je     80009c <primeproc+0x68>
			ipc_send(id, i, 0, 0);
  8000c1:	c7 44 24 0c 00 00 00 	movl   $0x0,0xc(%esp)
  8000c8:	00 
  8000c9:	c7 44 24 08 00 00 00 	movl   $0x0,0x8(%esp)
  8000d0:	00 
  8000d1:	89 4c 24 04          	mov    %ecx,0x4(%esp)
  8000d5:	89 3c 24             	mov    %edi,(%esp)
  8000d8:	e8 f3 14 00 00       	call   8015d0 <ipc_send>
  8000dd:	eb bd                	jmp    80009c <primeproc+0x68>

008000df <umain>:
	}
}

void
umain(void)
{
  8000df:	55                   	push   %ebp
  8000e0:	89 e5                	mov    %esp,%ebp
  8000e2:	56                   	push   %esi
  8000e3:	53                   	push   %ebx
  8000e4:	83 ec 10             	sub    $0x10,%esp
	int i, id;

	// fork the first prime process in the chain
	if ((id = fork()) < 0)
  8000e7:	e8 06 11 00 00       	call   8011f2 <fork>
  8000ec:	89 c6                	mov    %eax,%esi
  8000ee:	85 c0                	test   %eax,%eax
  8000f0:	79 20                	jns    800112 <umain+0x33>
		panic("fork: %e", id);
  8000f2:	89 44 24 0c          	mov    %eax,0xc(%esp)
  8000f6:	c7 44 24 08 84 2d 80 	movl   $0x802d84,0x8(%esp)
  8000fd:	00 
  8000fe:	c7 44 24 04 2d 00 00 	movl   $0x2d,0x4(%esp)
  800105:	00 
  800106:	c7 04 24 8d 2d 80 00 	movl   $0x802d8d,(%esp)
  80010d:	e8 9e 00 00 00       	call   8001b0 <_panic>
	if (id == 0)
  800112:	bb 02 00 00 00       	mov    $0x2,%ebx
  800117:	85 c0                	test   %eax,%eax
  800119:	75 05                	jne    800120 <umain+0x41>
		primeproc();
  80011b:	e8 14 ff ff ff       	call   800034 <primeproc>

	// feed all the integers through
	for (i = 2; ; i++)
		ipc_send(id, i, 0, 0);
  800120:	c7 44 24 0c 00 00 00 	movl   $0x0,0xc(%esp)
  800127:	00 
  800128:	c7 44 24 08 00 00 00 	movl   $0x0,0x8(%esp)
  80012f:	00 
  800130:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  800134:	89 34 24             	mov    %esi,(%esp)
  800137:	e8 94 14 00 00       	call   8015d0 <ipc_send>
		panic("fork: %e", id);
	if (id == 0)
		primeproc();

	// feed all the integers through
	for (i = 2; ; i++)
  80013c:	83 c3 01             	add    $0x1,%ebx
  80013f:	eb df                	jmp    800120 <umain+0x41>
  800141:	00 00                	add    %al,(%eax)
	...

00800144 <libmain>:
volatile struct Env *env;
char *binaryname = "(PROGRAM NAME UNKNOWN)";

void
libmain(int argc, char **argv)
{
  800144:	55                   	push   %ebp
  800145:	89 e5                	mov    %esp,%ebp
  800147:	83 ec 18             	sub    $0x18,%esp
  80014a:	89 5d f8             	mov    %ebx,-0x8(%ebp)
  80014d:	89 75 fc             	mov    %esi,-0x4(%ebp)
  800150:	8b 75 08             	mov    0x8(%ebp),%esi
  800153:	8b 5d 0c             	mov    0xc(%ebp),%ebx
	// set env to point at our env structure in envs[].
	// LAB 3: Your code here.
  envid_t envid   = sys_getenvid();
  800156:	e8 de 0f 00 00       	call   801139 <sys_getenvid>
	env = &envs [ENVX(envid)];
  80015b:	25 ff 03 00 00       	and    $0x3ff,%eax
  800160:	6b c0 7c             	imul   $0x7c,%eax,%eax
  800163:	05 00 00 c0 ee       	add    $0xeec00000,%eax
  800168:	a3 74 70 80 00       	mov    %eax,0x807074

	// save the name of the program so that panic() can use it
	if (argc > 0)
  80016d:	85 f6                	test   %esi,%esi
  80016f:	7e 07                	jle    800178 <libmain+0x34>
		binaryname = argv[0];
  800171:	8b 03                	mov    (%ebx),%eax
  800173:	a3 00 70 80 00       	mov    %eax,0x807000

	// call user main routine
	umain(argc, argv);
  800178:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  80017c:	89 34 24             	mov    %esi,(%esp)
  80017f:	e8 5b ff ff ff       	call   8000df <umain>

	// exit gracefully
	exit();
  800184:	e8 0b 00 00 00       	call   800194 <exit>
}
  800189:	8b 5d f8             	mov    -0x8(%ebp),%ebx
  80018c:	8b 75 fc             	mov    -0x4(%ebp),%esi
  80018f:	89 ec                	mov    %ebp,%esp
  800191:	5d                   	pop    %ebp
  800192:	c3                   	ret    
	...

00800194 <exit>:

#include <inc/lib.h>

void
exit(void)
{
  800194:	55                   	push   %ebp
  800195:	89 e5                	mov    %esp,%ebp
  800197:	83 ec 18             	sub    $0x18,%esp
	close_all();
  80019a:	e8 3a 1a 00 00       	call   801bd9 <close_all>
	sys_env_destroy(0);
  80019f:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  8001a6:	e8 c2 0f 00 00       	call   80116d <sys_env_destroy>
}
  8001ab:	c9                   	leave  
  8001ac:	c3                   	ret    
  8001ad:	00 00                	add    %al,(%eax)
	...

008001b0 <_panic>:
 * It prints "panic: <message>", then causes a breakpoint exception,
 * which causes JOS to enter the JOS kernel monitor.
 */
void
_panic(const char *file, int line, const char *fmt,...)
{
  8001b0:	55                   	push   %ebp
  8001b1:	89 e5                	mov    %esp,%ebp
  8001b3:	53                   	push   %ebx
  8001b4:	83 ec 14             	sub    $0x14,%esp
 * Panic is called on unresolvable fatal errors.
 * It prints "panic: <message>", then causes a breakpoint exception,
 * which causes JOS to enter the JOS kernel monitor.
 */
void
_panic(const char *file, int line, const char *fmt,...)
  8001b7:	8d 5d 14             	lea    0x14(%ebp),%ebx
	va_list ap;

	va_start(ap, fmt);

	// Print the panic message
	if (argv0)
  8001ba:	a1 78 70 80 00       	mov    0x807078,%eax
  8001bf:	85 c0                	test   %eax,%eax
  8001c1:	74 10                	je     8001d3 <_panic+0x23>
		cprintf("%s: ", argv0);
  8001c3:	89 44 24 04          	mov    %eax,0x4(%esp)
  8001c7:	c7 04 24 b2 2d 80 00 	movl   $0x802db2,(%esp)
  8001ce:	e8 a2 00 00 00       	call   800275 <cprintf>
	cprintf("user panic in %s at %s:%d: ", binaryname, file, line);
  8001d3:	8b 45 0c             	mov    0xc(%ebp),%eax
  8001d6:	89 44 24 0c          	mov    %eax,0xc(%esp)
  8001da:	8b 45 08             	mov    0x8(%ebp),%eax
  8001dd:	89 44 24 08          	mov    %eax,0x8(%esp)
  8001e1:	a1 00 70 80 00       	mov    0x807000,%eax
  8001e6:	89 44 24 04          	mov    %eax,0x4(%esp)
  8001ea:	c7 04 24 b7 2d 80 00 	movl   $0x802db7,(%esp)
  8001f1:	e8 7f 00 00 00       	call   800275 <cprintf>
	vcprintf(fmt, ap);
  8001f6:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  8001fa:	8b 45 10             	mov    0x10(%ebp),%eax
  8001fd:	89 04 24             	mov    %eax,(%esp)
  800200:	e8 0f 00 00 00       	call   800214 <vcprintf>
	cprintf("\n");
  800205:	c7 04 24 47 31 80 00 	movl   $0x803147,(%esp)
  80020c:	e8 64 00 00 00       	call   800275 <cprintf>

	// Cause a breakpoint exception
	while (1)
		asm volatile("int3");
  800211:	cc                   	int3   
  800212:	eb fd                	jmp    800211 <_panic+0x61>

00800214 <vcprintf>:
	b->cnt++;
}

int
vcprintf(const char *fmt, va_list ap)
{
  800214:	55                   	push   %ebp
  800215:	89 e5                	mov    %esp,%ebp
  800217:	81 ec 28 01 00 00    	sub    $0x128,%esp
	struct printbuf b;

	b.idx = 0;
  80021d:	c7 85 f0 fe ff ff 00 	movl   $0x0,-0x110(%ebp)
  800224:	00 00 00 
	b.cnt = 0;
  800227:	c7 85 f4 fe ff ff 00 	movl   $0x0,-0x10c(%ebp)
  80022e:	00 00 00 
	vprintfmt((void*)putch, &b, fmt, ap);
  800231:	8b 45 0c             	mov    0xc(%ebp),%eax
  800234:	89 44 24 0c          	mov    %eax,0xc(%esp)
  800238:	8b 45 08             	mov    0x8(%ebp),%eax
  80023b:	89 44 24 08          	mov    %eax,0x8(%esp)
  80023f:	8d 85 f0 fe ff ff    	lea    -0x110(%ebp),%eax
  800245:	89 44 24 04          	mov    %eax,0x4(%esp)
  800249:	c7 04 24 8f 02 80 00 	movl   $0x80028f,(%esp)
  800250:	e8 d8 01 00 00       	call   80042d <vprintfmt>
	sys_cputs(b.buf, b.idx);
  800255:	8b 85 f0 fe ff ff    	mov    -0x110(%ebp),%eax
  80025b:	89 44 24 04          	mov    %eax,0x4(%esp)
  80025f:	8d 85 f8 fe ff ff    	lea    -0x108(%ebp),%eax
  800265:	89 04 24             	mov    %eax,(%esp)
  800268:	e8 d3 0a 00 00       	call   800d40 <sys_cputs>

	return b.cnt;
}
  80026d:	8b 85 f4 fe ff ff    	mov    -0x10c(%ebp),%eax
  800273:	c9                   	leave  
  800274:	c3                   	ret    

00800275 <cprintf>:

int
cprintf(const char *fmt, ...)
{
  800275:	55                   	push   %ebp
  800276:	89 e5                	mov    %esp,%ebp
  800278:	83 ec 18             	sub    $0x18,%esp

	return b.cnt;
}

int
cprintf(const char *fmt, ...)
  80027b:	8d 45 0c             	lea    0xc(%ebp),%eax
{
	va_list ap;
	int cnt;

	va_start(ap, fmt);
	cnt = vcprintf(fmt, ap);
  80027e:	89 44 24 04          	mov    %eax,0x4(%esp)
  800282:	8b 45 08             	mov    0x8(%ebp),%eax
  800285:	89 04 24             	mov    %eax,(%esp)
  800288:	e8 87 ff ff ff       	call   800214 <vcprintf>
	va_end(ap);

	return cnt;
}
  80028d:	c9                   	leave  
  80028e:	c3                   	ret    

0080028f <putch>:
};


static void
putch(int ch, struct printbuf *b)
{
  80028f:	55                   	push   %ebp
  800290:	89 e5                	mov    %esp,%ebp
  800292:	53                   	push   %ebx
  800293:	83 ec 14             	sub    $0x14,%esp
  800296:	8b 5d 0c             	mov    0xc(%ebp),%ebx
	b->buf[b->idx++] = ch;
  800299:	8b 03                	mov    (%ebx),%eax
  80029b:	8b 55 08             	mov    0x8(%ebp),%edx
  80029e:	88 54 03 08          	mov    %dl,0x8(%ebx,%eax,1)
  8002a2:	83 c0 01             	add    $0x1,%eax
  8002a5:	89 03                	mov    %eax,(%ebx)
	if (b->idx == 256-1) {
  8002a7:	3d ff 00 00 00       	cmp    $0xff,%eax
  8002ac:	75 19                	jne    8002c7 <putch+0x38>
		sys_cputs(b->buf, b->idx);
  8002ae:	c7 44 24 04 ff 00 00 	movl   $0xff,0x4(%esp)
  8002b5:	00 
  8002b6:	8d 43 08             	lea    0x8(%ebx),%eax
  8002b9:	89 04 24             	mov    %eax,(%esp)
  8002bc:	e8 7f 0a 00 00       	call   800d40 <sys_cputs>
		b->idx = 0;
  8002c1:	c7 03 00 00 00 00    	movl   $0x0,(%ebx)
	}
	b->cnt++;
  8002c7:	83 43 04 01          	addl   $0x1,0x4(%ebx)
}
  8002cb:	83 c4 14             	add    $0x14,%esp
  8002ce:	5b                   	pop    %ebx
  8002cf:	5d                   	pop    %ebp
  8002d0:	c3                   	ret    
	...

008002e0 <printnum>:
 * using specified putch function and associated pointer putdat.
 */
static void
printnum(void (*putch)(int, void*), void *putdat,
	 unsigned long long num, unsigned base, int width, int padc)
{
  8002e0:	55                   	push   %ebp
  8002e1:	89 e5                	mov    %esp,%ebp
  8002e3:	57                   	push   %edi
  8002e4:	56                   	push   %esi
  8002e5:	53                   	push   %ebx
  8002e6:	83 ec 4c             	sub    $0x4c,%esp
  8002e9:	89 45 e4             	mov    %eax,-0x1c(%ebp)
  8002ec:	89 d6                	mov    %edx,%esi
  8002ee:	8b 45 08             	mov    0x8(%ebp),%eax
  8002f1:	89 45 d8             	mov    %eax,-0x28(%ebp)
  8002f4:	8b 55 0c             	mov    0xc(%ebp),%edx
  8002f7:	89 55 e0             	mov    %edx,-0x20(%ebp)
  8002fa:	8b 45 10             	mov    0x10(%ebp),%eax
  8002fd:	8b 5d 14             	mov    0x14(%ebp),%ebx
  800300:	8b 7d 18             	mov    0x18(%ebp),%edi
	// first recursively print all preceding (more significant) digits
	if (num >= base) {
  800303:	89 45 dc             	mov    %eax,-0x24(%ebp)
  800306:	b9 00 00 00 00       	mov    $0x0,%ecx
  80030b:	39 d1                	cmp    %edx,%ecx
  80030d:	72 15                	jb     800324 <printnum+0x44>
  80030f:	77 07                	ja     800318 <printnum+0x38>
  800311:	8b 55 d8             	mov    -0x28(%ebp),%edx
  800314:	39 d0                	cmp    %edx,%eax
  800316:	76 0c                	jbe    800324 <printnum+0x44>
		printnum(putch, putdat, num / base, base, width - 1, padc);
	} else {
		// print any needed pad characters before first digit
		while (--width > 0)
  800318:	83 eb 01             	sub    $0x1,%ebx
  80031b:	85 db                	test   %ebx,%ebx
  80031d:	8d 76 00             	lea    0x0(%esi),%esi
  800320:	7f 61                	jg     800383 <printnum+0xa3>
  800322:	eb 70                	jmp    800394 <printnum+0xb4>
printnum(void (*putch)(int, void*), void *putdat,
	 unsigned long long num, unsigned base, int width, int padc)
{
	// first recursively print all preceding (more significant) digits
	if (num >= base) {
		printnum(putch, putdat, num / base, base, width - 1, padc);
  800324:	89 7c 24 10          	mov    %edi,0x10(%esp)
  800328:	83 eb 01             	sub    $0x1,%ebx
  80032b:	89 5c 24 0c          	mov    %ebx,0xc(%esp)
  80032f:	89 44 24 08          	mov    %eax,0x8(%esp)
  800333:	8b 4c 24 08          	mov    0x8(%esp),%ecx
  800337:	8b 5c 24 0c          	mov    0xc(%esp),%ebx
  80033b:	89 4d d0             	mov    %ecx,-0x30(%ebp)
  80033e:	89 5d d4             	mov    %ebx,-0x2c(%ebp)
  800341:	8b 5d dc             	mov    -0x24(%ebp),%ebx
  800344:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  800348:	c7 44 24 0c 00 00 00 	movl   $0x0,0xc(%esp)
  80034f:	00 
  800350:	8b 45 d8             	mov    -0x28(%ebp),%eax
  800353:	89 04 24             	mov    %eax,(%esp)
  800356:	8b 55 e0             	mov    -0x20(%ebp),%edx
  800359:	89 54 24 04          	mov    %edx,0x4(%esp)
  80035d:	e8 ae 27 00 00       	call   802b10 <__udivdi3>
  800362:	8b 4d d0             	mov    -0x30(%ebp),%ecx
  800365:	8b 5d d4             	mov    -0x2c(%ebp),%ebx
  800368:	89 4c 24 08          	mov    %ecx,0x8(%esp)
  80036c:	89 5c 24 0c          	mov    %ebx,0xc(%esp)
  800370:	89 04 24             	mov    %eax,(%esp)
  800373:	89 54 24 04          	mov    %edx,0x4(%esp)
  800377:	89 f2                	mov    %esi,%edx
  800379:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  80037c:	e8 5f ff ff ff       	call   8002e0 <printnum>
  800381:	eb 11                	jmp    800394 <printnum+0xb4>
	} else {
		// print any needed pad characters before first digit
		while (--width > 0)
			putch(padc, putdat);
  800383:	89 74 24 04          	mov    %esi,0x4(%esp)
  800387:	89 3c 24             	mov    %edi,(%esp)
  80038a:	ff 55 e4             	call   *-0x1c(%ebp)
	// first recursively print all preceding (more significant) digits
	if (num >= base) {
		printnum(putch, putdat, num / base, base, width - 1, padc);
	} else {
		// print any needed pad characters before first digit
		while (--width > 0)
  80038d:	83 eb 01             	sub    $0x1,%ebx
  800390:	85 db                	test   %ebx,%ebx
  800392:	7f ef                	jg     800383 <printnum+0xa3>
			putch(padc, putdat);
	}

	// then print this (the least significant) digit
	putch("0123456789abcdef"[num % base], putdat);
  800394:	89 74 24 04          	mov    %esi,0x4(%esp)
  800398:	8b 74 24 04          	mov    0x4(%esp),%esi
  80039c:	8b 45 dc             	mov    -0x24(%ebp),%eax
  80039f:	89 44 24 08          	mov    %eax,0x8(%esp)
  8003a3:	c7 44 24 0c 00 00 00 	movl   $0x0,0xc(%esp)
  8003aa:	00 
  8003ab:	8b 55 d8             	mov    -0x28(%ebp),%edx
  8003ae:	89 14 24             	mov    %edx,(%esp)
  8003b1:	8b 4d e0             	mov    -0x20(%ebp),%ecx
  8003b4:	89 4c 24 04          	mov    %ecx,0x4(%esp)
  8003b8:	e8 83 28 00 00       	call   802c40 <__umoddi3>
  8003bd:	89 74 24 04          	mov    %esi,0x4(%esp)
  8003c1:	0f be 80 d3 2d 80 00 	movsbl 0x802dd3(%eax),%eax
  8003c8:	89 04 24             	mov    %eax,(%esp)
  8003cb:	ff 55 e4             	call   *-0x1c(%ebp)
}
  8003ce:	83 c4 4c             	add    $0x4c,%esp
  8003d1:	5b                   	pop    %ebx
  8003d2:	5e                   	pop    %esi
  8003d3:	5f                   	pop    %edi
  8003d4:	5d                   	pop    %ebp
  8003d5:	c3                   	ret    

008003d6 <getuint>:

// Get an unsigned int of various possible sizes from a varargs list,
// depending on the lflag parameter.
static unsigned long long
getuint(va_list *ap, int lflag)
{
  8003d6:	55                   	push   %ebp
  8003d7:	89 e5                	mov    %esp,%ebp
	if (lflag >= 2)
  8003d9:	83 fa 01             	cmp    $0x1,%edx
  8003dc:	7e 0e                	jle    8003ec <getuint+0x16>
		return va_arg(*ap, unsigned long long);
  8003de:	8b 10                	mov    (%eax),%edx
  8003e0:	8d 4a 08             	lea    0x8(%edx),%ecx
  8003e3:	89 08                	mov    %ecx,(%eax)
  8003e5:	8b 02                	mov    (%edx),%eax
  8003e7:	8b 52 04             	mov    0x4(%edx),%edx
  8003ea:	eb 22                	jmp    80040e <getuint+0x38>
	else if (lflag)
  8003ec:	85 d2                	test   %edx,%edx
  8003ee:	74 10                	je     800400 <getuint+0x2a>
		return va_arg(*ap, unsigned long);
  8003f0:	8b 10                	mov    (%eax),%edx
  8003f2:	8d 4a 04             	lea    0x4(%edx),%ecx
  8003f5:	89 08                	mov    %ecx,(%eax)
  8003f7:	8b 02                	mov    (%edx),%eax
  8003f9:	ba 00 00 00 00       	mov    $0x0,%edx
  8003fe:	eb 0e                	jmp    80040e <getuint+0x38>
	else
		return va_arg(*ap, unsigned int);
  800400:	8b 10                	mov    (%eax),%edx
  800402:	8d 4a 04             	lea    0x4(%edx),%ecx
  800405:	89 08                	mov    %ecx,(%eax)
  800407:	8b 02                	mov    (%edx),%eax
  800409:	ba 00 00 00 00       	mov    $0x0,%edx
}
  80040e:	5d                   	pop    %ebp
  80040f:	c3                   	ret    

00800410 <sprintputch>:
	int cnt;
};

static void
sprintputch(int ch, struct sprintbuf *b)
{
  800410:	55                   	push   %ebp
  800411:	89 e5                	mov    %esp,%ebp
  800413:	8b 45 0c             	mov    0xc(%ebp),%eax
	b->cnt++;
  800416:	83 40 08 01          	addl   $0x1,0x8(%eax)
	if (b->buf < b->ebuf)
  80041a:	8b 10                	mov    (%eax),%edx
  80041c:	3b 50 04             	cmp    0x4(%eax),%edx
  80041f:	73 0a                	jae    80042b <sprintputch+0x1b>
		*b->buf++ = ch;
  800421:	8b 4d 08             	mov    0x8(%ebp),%ecx
  800424:	88 0a                	mov    %cl,(%edx)
  800426:	83 c2 01             	add    $0x1,%edx
  800429:	89 10                	mov    %edx,(%eax)
}
  80042b:	5d                   	pop    %ebp
  80042c:	c3                   	ret    

0080042d <vprintfmt>:
// Main function to format and print a string.
void printfmt(void (*putch)(int, void*), void *putdat, const char *fmt, ...);

void
vprintfmt(void (*putch)(int, void*), void *putdat, const char *fmt, va_list ap)
{
  80042d:	55                   	push   %ebp
  80042e:	89 e5                	mov    %esp,%ebp
  800430:	57                   	push   %edi
  800431:	56                   	push   %esi
  800432:	53                   	push   %ebx
  800433:	83 ec 5c             	sub    $0x5c,%esp
  800436:	8b 7d 08             	mov    0x8(%ebp),%edi
  800439:	8b 75 0c             	mov    0xc(%ebp),%esi
  80043c:	8b 5d 10             	mov    0x10(%ebp),%ebx
		case '#':
			altflag = 1;
			goto reswitch;

		process_precision:
			if (width < 0)
  80043f:	c7 45 c8 ff ff ff ff 	movl   $0xffffffff,-0x38(%ebp)
  800446:	eb 11                	jmp    800459 <vprintfmt+0x2c>
	int base, lflag, width, precision, altflag;
	char padc;

	while (1) {
		while ((ch = *(unsigned char *) fmt++) != '%') {
			if (ch == '\0')
  800448:	85 c0                	test   %eax,%eax
  80044a:	0f 84 f9 03 00 00    	je     800849 <vprintfmt+0x41c>
				return;
			putch(ch, putdat);
  800450:	89 74 24 04          	mov    %esi,0x4(%esp)
  800454:	89 04 24             	mov    %eax,(%esp)
  800457:	ff d7                	call   *%edi
	unsigned long long num;
	int base, lflag, width, precision, altflag;
	char padc;

	while (1) {
		while ((ch = *(unsigned char *) fmt++) != '%') {
  800459:	0f b6 03             	movzbl (%ebx),%eax
  80045c:	83 c3 01             	add    $0x1,%ebx
  80045f:	83 f8 25             	cmp    $0x25,%eax
  800462:	75 e4                	jne    800448 <vprintfmt+0x1b>
  800464:	c6 45 d4 20          	movb   $0x20,-0x2c(%ebp)
  800468:	c7 45 d8 00 00 00 00 	movl   $0x0,-0x28(%ebp)
  80046f:	c7 45 d0 ff ff ff ff 	movl   $0xffffffff,-0x30(%ebp)
  800476:	c7 45 e4 ff ff ff ff 	movl   $0xffffffff,-0x1c(%ebp)
  80047d:	b9 00 00 00 00       	mov    $0x0,%ecx
  800482:	eb 06                	jmp    80048a <vprintfmt+0x5d>
  800484:	c6 45 d4 2d          	movb   $0x2d,-0x2c(%ebp)
  800488:	89 c3                	mov    %eax,%ebx
		width = -1;
		precision = -1;
		lflag = 0;
		altflag = 0;
	reswitch:
		switch (ch = *(unsigned char *) fmt++) {
  80048a:	0f b6 13             	movzbl (%ebx),%edx
  80048d:	0f b6 c2             	movzbl %dl,%eax
  800490:	89 45 e0             	mov    %eax,-0x20(%ebp)
  800493:	8d 43 01             	lea    0x1(%ebx),%eax
  800496:	83 ea 23             	sub    $0x23,%edx
  800499:	80 fa 55             	cmp    $0x55,%dl
  80049c:	0f 87 8a 03 00 00    	ja     80082c <vprintfmt+0x3ff>
  8004a2:	0f b6 d2             	movzbl %dl,%edx
  8004a5:	ff 24 95 20 2f 80 00 	jmp    *0x802f20(,%edx,4)
  8004ac:	c6 45 d4 30          	movb   $0x30,-0x2c(%ebp)
  8004b0:	eb d6                	jmp    800488 <vprintfmt+0x5b>
		case '6':
		case '7':
		case '8':
		case '9':
			for (precision = 0; ; ++fmt) {
				precision = precision * 10 + ch - '0';
  8004b2:	8b 55 e0             	mov    -0x20(%ebp),%edx
  8004b5:	83 ea 30             	sub    $0x30,%edx
  8004b8:	89 55 d0             	mov    %edx,-0x30(%ebp)
				ch = *fmt;
  8004bb:	0f be 10             	movsbl (%eax),%edx
				if (ch < '0' || ch > '9')
  8004be:	8d 5a d0             	lea    -0x30(%edx),%ebx
  8004c1:	83 fb 09             	cmp    $0x9,%ebx
  8004c4:	77 54                	ja     80051a <vprintfmt+0xed>
  8004c6:	89 4d e0             	mov    %ecx,-0x20(%ebp)
  8004c9:	8b 4d d0             	mov    -0x30(%ebp),%ecx
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
			for (precision = 0; ; ++fmt) {
  8004cc:	83 c0 01             	add    $0x1,%eax
				precision = precision * 10 + ch - '0';
  8004cf:	8d 0c 89             	lea    (%ecx,%ecx,4),%ecx
  8004d2:	8d 4c 4a d0          	lea    -0x30(%edx,%ecx,2),%ecx
				ch = *fmt;
  8004d6:	0f be 10             	movsbl (%eax),%edx
				if (ch < '0' || ch > '9')
  8004d9:	8d 5a d0             	lea    -0x30(%edx),%ebx
  8004dc:	83 fb 09             	cmp    $0x9,%ebx
  8004df:	76 eb                	jbe    8004cc <vprintfmt+0x9f>
  8004e1:	89 4d d0             	mov    %ecx,-0x30(%ebp)
  8004e4:	8b 4d e0             	mov    -0x20(%ebp),%ecx
  8004e7:	eb 31                	jmp    80051a <vprintfmt+0xed>
					break;
			}
			goto process_precision;

		case '*':
			precision = va_arg(ap, int);
  8004e9:	8b 55 14             	mov    0x14(%ebp),%edx
  8004ec:	8d 5a 04             	lea    0x4(%edx),%ebx
  8004ef:	89 5d 14             	mov    %ebx,0x14(%ebp)
  8004f2:	8b 12                	mov    (%edx),%edx
  8004f4:	89 55 d0             	mov    %edx,-0x30(%ebp)
			goto process_precision;
  8004f7:	eb 21                	jmp    80051a <vprintfmt+0xed>

		case '.':
			if (width < 0)
  8004f9:	83 7d e4 00          	cmpl   $0x0,-0x1c(%ebp)
  8004fd:	ba 00 00 00 00       	mov    $0x0,%edx
  800502:	0f 49 55 e4          	cmovns -0x1c(%ebp),%edx
  800506:	89 55 e4             	mov    %edx,-0x1c(%ebp)
  800509:	e9 7a ff ff ff       	jmp    800488 <vprintfmt+0x5b>
  80050e:	c7 45 d8 01 00 00 00 	movl   $0x1,-0x28(%ebp)
				width = 0;
			goto reswitch;

		case '#':
			altflag = 1;
			goto reswitch;
  800515:	e9 6e ff ff ff       	jmp    800488 <vprintfmt+0x5b>

		process_precision:
			if (width < 0)
  80051a:	83 7d e4 00          	cmpl   $0x0,-0x1c(%ebp)
  80051e:	0f 89 64 ff ff ff    	jns    800488 <vprintfmt+0x5b>
  800524:	8b 55 d0             	mov    -0x30(%ebp),%edx
  800527:	89 55 e4             	mov    %edx,-0x1c(%ebp)
  80052a:	8b 55 c8             	mov    -0x38(%ebp),%edx
  80052d:	89 55 d0             	mov    %edx,-0x30(%ebp)
  800530:	e9 53 ff ff ff       	jmp    800488 <vprintfmt+0x5b>
				width = precision, precision = -1;
			goto reswitch;

		// long flag (doubled for long long)
		case 'l':
			lflag++;
  800535:	83 c1 01             	add    $0x1,%ecx
			goto reswitch;
  800538:	e9 4b ff ff ff       	jmp    800488 <vprintfmt+0x5b>
  80053d:	89 45 cc             	mov    %eax,-0x34(%ebp)

		// character
		case 'c':
			putch(va_arg(ap, int), putdat);
  800540:	8b 45 14             	mov    0x14(%ebp),%eax
  800543:	8d 50 04             	lea    0x4(%eax),%edx
  800546:	89 55 14             	mov    %edx,0x14(%ebp)
  800549:	89 74 24 04          	mov    %esi,0x4(%esp)
  80054d:	8b 00                	mov    (%eax),%eax
  80054f:	89 04 24             	mov    %eax,(%esp)
  800552:	ff d7                	call   *%edi
  800554:	8b 5d cc             	mov    -0x34(%ebp),%ebx
			break;
  800557:	e9 fd fe ff ff       	jmp    800459 <vprintfmt+0x2c>
  80055c:	89 45 cc             	mov    %eax,-0x34(%ebp)

		// error message
		case 'e':
			err = va_arg(ap, int);
  80055f:	8b 45 14             	mov    0x14(%ebp),%eax
  800562:	8d 50 04             	lea    0x4(%eax),%edx
  800565:	89 55 14             	mov    %edx,0x14(%ebp)
  800568:	8b 00                	mov    (%eax),%eax
  80056a:	89 c2                	mov    %eax,%edx
  80056c:	c1 fa 1f             	sar    $0x1f,%edx
  80056f:	31 d0                	xor    %edx,%eax
  800571:	29 d0                	sub    %edx,%eax
			if (err < 0)
				err = -err;
			if (err > MAXERROR || (p = error_string[err]) == NULL)
  800573:	83 f8 12             	cmp    $0x12,%eax
  800576:	7f 0b                	jg     800583 <vprintfmt+0x156>
  800578:	8b 14 85 80 30 80 00 	mov    0x803080(,%eax,4),%edx
  80057f:	85 d2                	test   %edx,%edx
  800581:	75 20                	jne    8005a3 <vprintfmt+0x176>
				printfmt(putch, putdat, "error %d", err);
  800583:	89 44 24 0c          	mov    %eax,0xc(%esp)
  800587:	c7 44 24 08 e4 2d 80 	movl   $0x802de4,0x8(%esp)
  80058e:	00 
  80058f:	89 74 24 04          	mov    %esi,0x4(%esp)
  800593:	89 3c 24             	mov    %edi,(%esp)
  800596:	e8 36 03 00 00       	call   8008d1 <printfmt>
  80059b:	8b 5d cc             	mov    -0x34(%ebp),%ebx
		// error message
		case 'e':
			err = va_arg(ap, int);
			if (err < 0)
				err = -err;
			if (err > MAXERROR || (p = error_string[err]) == NULL)
  80059e:	e9 b6 fe ff ff       	jmp    800459 <vprintfmt+0x2c>
				printfmt(putch, putdat, "error %d", err);
			else
				printfmt(putch, putdat, "%s", p);
  8005a3:	89 54 24 0c          	mov    %edx,0xc(%esp)
  8005a7:	c7 44 24 08 c2 33 80 	movl   $0x8033c2,0x8(%esp)
  8005ae:	00 
  8005af:	89 74 24 04          	mov    %esi,0x4(%esp)
  8005b3:	89 3c 24             	mov    %edi,(%esp)
  8005b6:	e8 16 03 00 00       	call   8008d1 <printfmt>
  8005bb:	8b 5d cc             	mov    -0x34(%ebp),%ebx
  8005be:	e9 96 fe ff ff       	jmp    800459 <vprintfmt+0x2c>
  8005c3:	89 45 cc             	mov    %eax,-0x34(%ebp)
  8005c6:	89 c3                	mov    %eax,%ebx
  8005c8:	8b 4d d0             	mov    -0x30(%ebp),%ecx
  8005cb:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  8005ce:	89 45 c4             	mov    %eax,-0x3c(%ebp)
			break;

		// string
		case 's':
			if ((p = va_arg(ap, char *)) == NULL)
  8005d1:	8b 45 14             	mov    0x14(%ebp),%eax
  8005d4:	8d 50 04             	lea    0x4(%eax),%edx
  8005d7:	89 55 14             	mov    %edx,0x14(%ebp)
  8005da:	8b 00                	mov    (%eax),%eax
  8005dc:	89 45 e0             	mov    %eax,-0x20(%ebp)
  8005df:	85 c0                	test   %eax,%eax
  8005e1:	b8 ed 2d 80 00       	mov    $0x802ded,%eax
  8005e6:	0f 45 45 e0          	cmovne -0x20(%ebp),%eax
  8005ea:	89 45 e0             	mov    %eax,-0x20(%ebp)
				p = "(null)";
			if (width > 0 && padc != '-')
  8005ed:	83 7d c4 00          	cmpl   $0x0,-0x3c(%ebp)
  8005f1:	7e 06                	jle    8005f9 <vprintfmt+0x1cc>
  8005f3:	80 7d d4 2d          	cmpb   $0x2d,-0x2c(%ebp)
  8005f7:	75 13                	jne    80060c <vprintfmt+0x1df>
				for (width -= strnlen(p, precision); width > 0; width--)
					putch(padc, putdat);
			for (; (ch = *p++) != '\0' && (precision < 0 || --precision >= 0); width--)
  8005f9:	8b 55 e0             	mov    -0x20(%ebp),%edx
  8005fc:	0f be 02             	movsbl (%edx),%eax
  8005ff:	85 c0                	test   %eax,%eax
  800601:	0f 85 9b 00 00 00    	jne    8006a2 <vprintfmt+0x275>
  800607:	e9 88 00 00 00       	jmp    800694 <vprintfmt+0x267>
		// string
		case 's':
			if ((p = va_arg(ap, char *)) == NULL)
				p = "(null)";
			if (width > 0 && padc != '-')
				for (width -= strnlen(p, precision); width > 0; width--)
  80060c:	89 4c 24 04          	mov    %ecx,0x4(%esp)
  800610:	8b 4d e0             	mov    -0x20(%ebp),%ecx
  800613:	89 0c 24             	mov    %ecx,(%esp)
  800616:	e8 00 03 00 00       	call   80091b <strnlen>
  80061b:	8b 55 c4             	mov    -0x3c(%ebp),%edx
  80061e:	29 c2                	sub    %eax,%edx
  800620:	89 55 e4             	mov    %edx,-0x1c(%ebp)
  800623:	85 d2                	test   %edx,%edx
  800625:	7e d2                	jle    8005f9 <vprintfmt+0x1cc>
					putch(padc, putdat);
  800627:	0f be 4d d4          	movsbl -0x2c(%ebp),%ecx
  80062b:	89 4d d4             	mov    %ecx,-0x2c(%ebp)
  80062e:	89 5d c4             	mov    %ebx,-0x3c(%ebp)
  800631:	89 d3                	mov    %edx,%ebx
  800633:	89 74 24 04          	mov    %esi,0x4(%esp)
  800637:	8b 45 d4             	mov    -0x2c(%ebp),%eax
  80063a:	89 04 24             	mov    %eax,(%esp)
  80063d:	ff d7                	call   *%edi
		// string
		case 's':
			if ((p = va_arg(ap, char *)) == NULL)
				p = "(null)";
			if (width > 0 && padc != '-')
				for (width -= strnlen(p, precision); width > 0; width--)
  80063f:	83 eb 01             	sub    $0x1,%ebx
  800642:	85 db                	test   %ebx,%ebx
  800644:	7f ed                	jg     800633 <vprintfmt+0x206>
  800646:	8b 5d c4             	mov    -0x3c(%ebp),%ebx
  800649:	c7 45 e4 00 00 00 00 	movl   $0x0,-0x1c(%ebp)
  800650:	eb a7                	jmp    8005f9 <vprintfmt+0x1cc>
					putch(padc, putdat);
			for (; (ch = *p++) != '\0' && (precision < 0 || --precision >= 0); width--)
				if (altflag && (ch < ' ' || ch > '~'))
  800652:	83 7d d8 00          	cmpl   $0x0,-0x28(%ebp)
  800656:	74 1a                	je     800672 <vprintfmt+0x245>
  800658:	8d 50 e0             	lea    -0x20(%eax),%edx
  80065b:	83 fa 5e             	cmp    $0x5e,%edx
  80065e:	76 12                	jbe    800672 <vprintfmt+0x245>
					putch('?', putdat);
  800660:	89 7c 24 04          	mov    %edi,0x4(%esp)
  800664:	c7 04 24 3f 00 00 00 	movl   $0x3f,(%esp)
  80066b:	ff 55 e0             	call   *-0x20(%ebp)
				p = "(null)";
			if (width > 0 && padc != '-')
				for (width -= strnlen(p, precision); width > 0; width--)
					putch(padc, putdat);
			for (; (ch = *p++) != '\0' && (precision < 0 || --precision >= 0); width--)
				if (altflag && (ch < ' ' || ch > '~'))
  80066e:	66 90                	xchg   %ax,%ax
  800670:	eb 0a                	jmp    80067c <vprintfmt+0x24f>
					putch('?', putdat);
				else
					putch(ch, putdat);
  800672:	89 7c 24 04          	mov    %edi,0x4(%esp)
  800676:	89 04 24             	mov    %eax,(%esp)
  800679:	ff 55 e0             	call   *-0x20(%ebp)
			if ((p = va_arg(ap, char *)) == NULL)
				p = "(null)";
			if (width > 0 && padc != '-')
				for (width -= strnlen(p, precision); width > 0; width--)
					putch(padc, putdat);
			for (; (ch = *p++) != '\0' && (precision < 0 || --precision >= 0); width--)
  80067c:	83 6d e4 01          	subl   $0x1,-0x1c(%ebp)
  800680:	0f be 03             	movsbl (%ebx),%eax
  800683:	85 c0                	test   %eax,%eax
  800685:	74 05                	je     80068c <vprintfmt+0x25f>
  800687:	83 c3 01             	add    $0x1,%ebx
  80068a:	eb 29                	jmp    8006b5 <vprintfmt+0x288>
  80068c:	89 fe                	mov    %edi,%esi
  80068e:	8b 7d e0             	mov    -0x20(%ebp),%edi
  800691:	8b 5d d0             	mov    -0x30(%ebp),%ebx
				if (altflag && (ch < ' ' || ch > '~'))
					putch('?', putdat);
				else
					putch(ch, putdat);
			for (; width > 0; width--)
  800694:	83 7d e4 00          	cmpl   $0x0,-0x1c(%ebp)
  800698:	7f 2e                	jg     8006c8 <vprintfmt+0x29b>
  80069a:	8b 5d cc             	mov    -0x34(%ebp),%ebx
  80069d:	e9 b7 fd ff ff       	jmp    800459 <vprintfmt+0x2c>
			if ((p = va_arg(ap, char *)) == NULL)
				p = "(null)";
			if (width > 0 && padc != '-')
				for (width -= strnlen(p, precision); width > 0; width--)
					putch(padc, putdat);
			for (; (ch = *p++) != '\0' && (precision < 0 || --precision >= 0); width--)
  8006a2:	8b 55 e0             	mov    -0x20(%ebp),%edx
  8006a5:	83 c2 01             	add    $0x1,%edx
  8006a8:	89 7d e0             	mov    %edi,-0x20(%ebp)
  8006ab:	89 f7                	mov    %esi,%edi
  8006ad:	8b 75 d0             	mov    -0x30(%ebp),%esi
  8006b0:	89 5d d0             	mov    %ebx,-0x30(%ebp)
  8006b3:	89 d3                	mov    %edx,%ebx
  8006b5:	85 f6                	test   %esi,%esi
  8006b7:	78 99                	js     800652 <vprintfmt+0x225>
  8006b9:	83 ee 01             	sub    $0x1,%esi
  8006bc:	79 94                	jns    800652 <vprintfmt+0x225>
  8006be:	89 fe                	mov    %edi,%esi
  8006c0:	8b 7d e0             	mov    -0x20(%ebp),%edi
  8006c3:	8b 5d d0             	mov    -0x30(%ebp),%ebx
  8006c6:	eb cc                	jmp    800694 <vprintfmt+0x267>
  8006c8:	89 5d d8             	mov    %ebx,-0x28(%ebp)
  8006cb:	8b 5d e4             	mov    -0x1c(%ebp),%ebx
				if (altflag && (ch < ' ' || ch > '~'))
					putch('?', putdat);
				else
					putch(ch, putdat);
			for (; width > 0; width--)
				putch(' ', putdat);
  8006ce:	89 74 24 04          	mov    %esi,0x4(%esp)
  8006d2:	c7 04 24 20 00 00 00 	movl   $0x20,(%esp)
  8006d9:	ff d7                	call   *%edi
			for (; (ch = *p++) != '\0' && (precision < 0 || --precision >= 0); width--)
				if (altflag && (ch < ' ' || ch > '~'))
					putch('?', putdat);
				else
					putch(ch, putdat);
			for (; width > 0; width--)
  8006db:	83 eb 01             	sub    $0x1,%ebx
  8006de:	85 db                	test   %ebx,%ebx
  8006e0:	7f ec                	jg     8006ce <vprintfmt+0x2a1>
  8006e2:	8b 5d d8             	mov    -0x28(%ebp),%ebx
  8006e5:	e9 6f fd ff ff       	jmp    800459 <vprintfmt+0x2c>
  8006ea:	89 45 cc             	mov    %eax,-0x34(%ebp)
// Same as getuint but signed - can't use getuint
// because of sign extension
static long long
getint(va_list *ap, int lflag)
{
	if (lflag >= 2)
  8006ed:	83 f9 01             	cmp    $0x1,%ecx
  8006f0:	7e 16                	jle    800708 <vprintfmt+0x2db>
		return va_arg(*ap, long long);
  8006f2:	8b 45 14             	mov    0x14(%ebp),%eax
  8006f5:	8d 50 08             	lea    0x8(%eax),%edx
  8006f8:	89 55 14             	mov    %edx,0x14(%ebp)
  8006fb:	8b 10                	mov    (%eax),%edx
  8006fd:	8b 48 04             	mov    0x4(%eax),%ecx
  800700:	89 55 d8             	mov    %edx,-0x28(%ebp)
  800703:	89 4d dc             	mov    %ecx,-0x24(%ebp)
  800706:	eb 32                	jmp    80073a <vprintfmt+0x30d>
	else if (lflag)
  800708:	85 c9                	test   %ecx,%ecx
  80070a:	74 18                	je     800724 <vprintfmt+0x2f7>
		return va_arg(*ap, long);
  80070c:	8b 45 14             	mov    0x14(%ebp),%eax
  80070f:	8d 50 04             	lea    0x4(%eax),%edx
  800712:	89 55 14             	mov    %edx,0x14(%ebp)
  800715:	8b 00                	mov    (%eax),%eax
  800717:	89 45 d8             	mov    %eax,-0x28(%ebp)
  80071a:	89 c1                	mov    %eax,%ecx
  80071c:	c1 f9 1f             	sar    $0x1f,%ecx
  80071f:	89 4d dc             	mov    %ecx,-0x24(%ebp)
  800722:	eb 16                	jmp    80073a <vprintfmt+0x30d>
	else
		return va_arg(*ap, int);
  800724:	8b 45 14             	mov    0x14(%ebp),%eax
  800727:	8d 50 04             	lea    0x4(%eax),%edx
  80072a:	89 55 14             	mov    %edx,0x14(%ebp)
  80072d:	8b 00                	mov    (%eax),%eax
  80072f:	89 45 d8             	mov    %eax,-0x28(%ebp)
  800732:	89 c2                	mov    %eax,%edx
  800734:	c1 fa 1f             	sar    $0x1f,%edx
  800737:	89 55 dc             	mov    %edx,-0x24(%ebp)
				putch(' ', putdat);
			break;

		// (signed) decimal
		case 'd':
			num = getint(&ap, lflag);
  80073a:	8b 4d d8             	mov    -0x28(%ebp),%ecx
  80073d:	8b 5d dc             	mov    -0x24(%ebp),%ebx
  800740:	b8 0a 00 00 00       	mov    $0xa,%eax
			if ((long long) num < 0) {
  800745:	83 7d dc 00          	cmpl   $0x0,-0x24(%ebp)
  800749:	0f 89 9b 00 00 00    	jns    8007ea <vprintfmt+0x3bd>
				putch('-', putdat);
  80074f:	89 74 24 04          	mov    %esi,0x4(%esp)
  800753:	c7 04 24 2d 00 00 00 	movl   $0x2d,(%esp)
  80075a:	ff d7                	call   *%edi
				num = -(long long) num;
  80075c:	8b 4d d8             	mov    -0x28(%ebp),%ecx
  80075f:	8b 5d dc             	mov    -0x24(%ebp),%ebx
  800762:	f7 d9                	neg    %ecx
  800764:	83 d3 00             	adc    $0x0,%ebx
  800767:	f7 db                	neg    %ebx
  800769:	b8 0a 00 00 00       	mov    $0xa,%eax
  80076e:	eb 7a                	jmp    8007ea <vprintfmt+0x3bd>
  800770:	89 45 cc             	mov    %eax,-0x34(%ebp)
			base = 10;
			goto number;

		// unsigned decimal
		case 'u':
			num = getuint(&ap, lflag);
  800773:	89 ca                	mov    %ecx,%edx
  800775:	8d 45 14             	lea    0x14(%ebp),%eax
  800778:	e8 59 fc ff ff       	call   8003d6 <getuint>
  80077d:	89 c1                	mov    %eax,%ecx
  80077f:	89 d3                	mov    %edx,%ebx
  800781:	b8 0a 00 00 00       	mov    $0xa,%eax
			base = 10;
			goto number;
  800786:	eb 62                	jmp    8007ea <vprintfmt+0x3bd>
  800788:	89 45 cc             	mov    %eax,-0x34(%ebp)

		// (unsigned) octal
		case 'o':
			num = getuint(&ap, lflag);
  80078b:	89 ca                	mov    %ecx,%edx
  80078d:	8d 45 14             	lea    0x14(%ebp),%eax
  800790:	e8 41 fc ff ff       	call   8003d6 <getuint>
  800795:	89 c1                	mov    %eax,%ecx
  800797:	89 d3                	mov    %edx,%ebx
  800799:	b8 08 00 00 00       	mov    $0x8,%eax
			base = 8;
			goto number;
  80079e:	eb 4a                	jmp    8007ea <vprintfmt+0x3bd>
  8007a0:	89 45 cc             	mov    %eax,-0x34(%ebp)
			break;
			**/

		// pointer
		case 'p':
			putch('0', putdat);
  8007a3:	89 74 24 04          	mov    %esi,0x4(%esp)
  8007a7:	c7 04 24 30 00 00 00 	movl   $0x30,(%esp)
  8007ae:	ff d7                	call   *%edi
			putch('x', putdat);
  8007b0:	89 74 24 04          	mov    %esi,0x4(%esp)
  8007b4:	c7 04 24 78 00 00 00 	movl   $0x78,(%esp)
  8007bb:	ff d7                	call   *%edi
			num = (unsigned long long)
  8007bd:	8b 45 14             	mov    0x14(%ebp),%eax
  8007c0:	8d 50 04             	lea    0x4(%eax),%edx
  8007c3:	89 55 14             	mov    %edx,0x14(%ebp)
  8007c6:	8b 08                	mov    (%eax),%ecx
  8007c8:	bb 00 00 00 00       	mov    $0x0,%ebx
  8007cd:	b8 10 00 00 00       	mov    $0x10,%eax
				(uintptr_t) va_arg(ap, void *);
			base = 16;
			goto number;
  8007d2:	eb 16                	jmp    8007ea <vprintfmt+0x3bd>
  8007d4:	89 45 cc             	mov    %eax,-0x34(%ebp)

		// (unsigned) hexadecimal
		case 'x':
			num = getuint(&ap, lflag);
  8007d7:	89 ca                	mov    %ecx,%edx
  8007d9:	8d 45 14             	lea    0x14(%ebp),%eax
  8007dc:	e8 f5 fb ff ff       	call   8003d6 <getuint>
  8007e1:	89 c1                	mov    %eax,%ecx
  8007e3:	89 d3                	mov    %edx,%ebx
  8007e5:	b8 10 00 00 00       	mov    $0x10,%eax
			base = 16;
		number:
			printnum(putch, putdat, num, base, width, padc);
  8007ea:	0f be 55 d4          	movsbl -0x2c(%ebp),%edx
  8007ee:	89 54 24 10          	mov    %edx,0x10(%esp)
  8007f2:	8b 55 e4             	mov    -0x1c(%ebp),%edx
  8007f5:	89 54 24 0c          	mov    %edx,0xc(%esp)
  8007f9:	89 44 24 08          	mov    %eax,0x8(%esp)
  8007fd:	89 0c 24             	mov    %ecx,(%esp)
  800800:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  800804:	89 f2                	mov    %esi,%edx
  800806:	89 f8                	mov    %edi,%eax
  800808:	e8 d3 fa ff ff       	call   8002e0 <printnum>
  80080d:	8b 5d cc             	mov    -0x34(%ebp),%ebx
			break;
  800810:	e9 44 fc ff ff       	jmp    800459 <vprintfmt+0x2c>
  800815:	89 45 cc             	mov    %eax,-0x34(%ebp)
  800818:	8b 55 e0             	mov    -0x20(%ebp),%edx

		// escaped '%' character
		case '%':
			putch(ch, putdat);
  80081b:	89 74 24 04          	mov    %esi,0x4(%esp)
  80081f:	89 14 24             	mov    %edx,(%esp)
  800822:	ff d7                	call   *%edi
  800824:	8b 5d cc             	mov    -0x34(%ebp),%ebx
			break;
  800827:	e9 2d fc ff ff       	jmp    800459 <vprintfmt+0x2c>
			
		// unrecognized escape sequence - just print it literally
		default:
			putch('%', putdat);
  80082c:	89 74 24 04          	mov    %esi,0x4(%esp)
  800830:	c7 04 24 25 00 00 00 	movl   $0x25,(%esp)
  800837:	ff d7                	call   *%edi
			for (fmt--; fmt[-1] != '%'; fmt--)
  800839:	8d 43 ff             	lea    -0x1(%ebx),%eax
  80083c:	80 38 25             	cmpb   $0x25,(%eax)
  80083f:	0f 84 14 fc ff ff    	je     800459 <vprintfmt+0x2c>
  800845:	89 c3                	mov    %eax,%ebx
  800847:	eb f0                	jmp    800839 <vprintfmt+0x40c>
				/* do nothing */;
			break;
		}
	}
}
  800849:	83 c4 5c             	add    $0x5c,%esp
  80084c:	5b                   	pop    %ebx
  80084d:	5e                   	pop    %esi
  80084e:	5f                   	pop    %edi
  80084f:	5d                   	pop    %ebp
  800850:	c3                   	ret    

00800851 <vsnprintf>:
		*b->buf++ = ch;
}

int
vsnprintf(char *buf, int n, const char *fmt, va_list ap)
{
  800851:	55                   	push   %ebp
  800852:	89 e5                	mov    %esp,%ebp
  800854:	83 ec 28             	sub    $0x28,%esp
  800857:	8b 45 08             	mov    0x8(%ebp),%eax
  80085a:	8b 55 0c             	mov    0xc(%ebp),%edx
	struct sprintbuf b = {buf, buf+n-1, 0};

	if (buf == NULL || n < 1)
  80085d:	85 c0                	test   %eax,%eax
  80085f:	74 04                	je     800865 <vsnprintf+0x14>
  800861:	85 d2                	test   %edx,%edx
  800863:	7f 07                	jg     80086c <vsnprintf+0x1b>
  800865:	b8 fd ff ff ff       	mov    $0xfffffffd,%eax
  80086a:	eb 3b                	jmp    8008a7 <vsnprintf+0x56>
}

int
vsnprintf(char *buf, int n, const char *fmt, va_list ap)
{
	struct sprintbuf b = {buf, buf+n-1, 0};
  80086c:	89 45 ec             	mov    %eax,-0x14(%ebp)
  80086f:	8d 44 10 ff          	lea    -0x1(%eax,%edx,1),%eax
  800873:	89 45 f0             	mov    %eax,-0x10(%ebp)
  800876:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)

	if (buf == NULL || n < 1)
		return -E_INVAL;

	// print the string to the buffer
	vprintfmt((void*)sprintputch, &b, fmt, ap);
  80087d:	8b 45 14             	mov    0x14(%ebp),%eax
  800880:	89 44 24 0c          	mov    %eax,0xc(%esp)
  800884:	8b 45 10             	mov    0x10(%ebp),%eax
  800887:	89 44 24 08          	mov    %eax,0x8(%esp)
  80088b:	8d 45 ec             	lea    -0x14(%ebp),%eax
  80088e:	89 44 24 04          	mov    %eax,0x4(%esp)
  800892:	c7 04 24 10 04 80 00 	movl   $0x800410,(%esp)
  800899:	e8 8f fb ff ff       	call   80042d <vprintfmt>

	// null terminate the buffer
	*b.buf = '\0';
  80089e:	8b 45 ec             	mov    -0x14(%ebp),%eax
  8008a1:	c6 00 00             	movb   $0x0,(%eax)

	return b.cnt;
  8008a4:	8b 45 f4             	mov    -0xc(%ebp),%eax
}
  8008a7:	c9                   	leave  
  8008a8:	c3                   	ret    

008008a9 <snprintf>:

int
snprintf(char *buf, int n, const char *fmt, ...)
{
  8008a9:	55                   	push   %ebp
  8008aa:	89 e5                	mov    %esp,%ebp
  8008ac:	83 ec 18             	sub    $0x18,%esp

	return b.cnt;
}

int
snprintf(char *buf, int n, const char *fmt, ...)
  8008af:	8d 45 14             	lea    0x14(%ebp),%eax
{
	va_list ap;
	int rc;

	va_start(ap, fmt);
	rc = vsnprintf(buf, n, fmt, ap);
  8008b2:	89 44 24 0c          	mov    %eax,0xc(%esp)
  8008b6:	8b 45 10             	mov    0x10(%ebp),%eax
  8008b9:	89 44 24 08          	mov    %eax,0x8(%esp)
  8008bd:	8b 45 0c             	mov    0xc(%ebp),%eax
  8008c0:	89 44 24 04          	mov    %eax,0x4(%esp)
  8008c4:	8b 45 08             	mov    0x8(%ebp),%eax
  8008c7:	89 04 24             	mov    %eax,(%esp)
  8008ca:	e8 82 ff ff ff       	call   800851 <vsnprintf>
	va_end(ap);

	return rc;
}
  8008cf:	c9                   	leave  
  8008d0:	c3                   	ret    

008008d1 <printfmt>:
	}
}

void
printfmt(void (*putch)(int, void*), void *putdat, const char *fmt, ...)
{
  8008d1:	55                   	push   %ebp
  8008d2:	89 e5                	mov    %esp,%ebp
  8008d4:	83 ec 18             	sub    $0x18,%esp
		}
	}
}

void
printfmt(void (*putch)(int, void*), void *putdat, const char *fmt, ...)
  8008d7:	8d 45 14             	lea    0x14(%ebp),%eax
{
	va_list ap;

	va_start(ap, fmt);
	vprintfmt(putch, putdat, fmt, ap);
  8008da:	89 44 24 0c          	mov    %eax,0xc(%esp)
  8008de:	8b 45 10             	mov    0x10(%ebp),%eax
  8008e1:	89 44 24 08          	mov    %eax,0x8(%esp)
  8008e5:	8b 45 0c             	mov    0xc(%ebp),%eax
  8008e8:	89 44 24 04          	mov    %eax,0x4(%esp)
  8008ec:	8b 45 08             	mov    0x8(%ebp),%eax
  8008ef:	89 04 24             	mov    %eax,(%esp)
  8008f2:	e8 36 fb ff ff       	call   80042d <vprintfmt>
	va_end(ap);
}
  8008f7:	c9                   	leave  
  8008f8:	c3                   	ret    
  8008f9:	00 00                	add    %al,(%eax)
  8008fb:	00 00                	add    %al,(%eax)
  8008fd:	00 00                	add    %al,(%eax)
	...

00800900 <strlen>:
// Primespipe runs 3x faster this way.
#define ASM 1

int
strlen(const char *s)
{
  800900:	55                   	push   %ebp
  800901:	89 e5                	mov    %esp,%ebp
  800903:	8b 55 08             	mov    0x8(%ebp),%edx
	int n;

	for (n = 0; *s != '\0'; s++)
  800906:	b8 00 00 00 00       	mov    $0x0,%eax
  80090b:	80 3a 00             	cmpb   $0x0,(%edx)
  80090e:	74 09                	je     800919 <strlen+0x19>
		n++;
  800910:	83 c0 01             	add    $0x1,%eax
int
strlen(const char *s)
{
	int n;

	for (n = 0; *s != '\0'; s++)
  800913:	80 3c 02 00          	cmpb   $0x0,(%edx,%eax,1)
  800917:	75 f7                	jne    800910 <strlen+0x10>
		n++;
	return n;
}
  800919:	5d                   	pop    %ebp
  80091a:	c3                   	ret    

0080091b <strnlen>:

int
strnlen(const char *s, size_t size)
{
  80091b:	55                   	push   %ebp
  80091c:	89 e5                	mov    %esp,%ebp
  80091e:	53                   	push   %ebx
  80091f:	8b 5d 08             	mov    0x8(%ebp),%ebx
  800922:	8b 4d 0c             	mov    0xc(%ebp),%ecx
	int n;

	for (n = 0; size > 0 && *s != '\0'; s++, size--)
  800925:	85 c9                	test   %ecx,%ecx
  800927:	74 19                	je     800942 <strnlen+0x27>
  800929:	80 3b 00             	cmpb   $0x0,(%ebx)
  80092c:	74 14                	je     800942 <strnlen+0x27>
  80092e:	b8 00 00 00 00       	mov    $0x0,%eax
		n++;
  800933:	83 c0 01             	add    $0x1,%eax
int
strnlen(const char *s, size_t size)
{
	int n;

	for (n = 0; size > 0 && *s != '\0'; s++, size--)
  800936:	39 c8                	cmp    %ecx,%eax
  800938:	74 0d                	je     800947 <strnlen+0x2c>
  80093a:	80 3c 03 00          	cmpb   $0x0,(%ebx,%eax,1)
  80093e:	75 f3                	jne    800933 <strnlen+0x18>
  800940:	eb 05                	jmp    800947 <strnlen+0x2c>
  800942:	b8 00 00 00 00       	mov    $0x0,%eax
		n++;
	return n;
}
  800947:	5b                   	pop    %ebx
  800948:	5d                   	pop    %ebp
  800949:	c3                   	ret    

0080094a <strcpy>:

char *
strcpy(char *dst, const char *src)
{
  80094a:	55                   	push   %ebp
  80094b:	89 e5                	mov    %esp,%ebp
  80094d:	53                   	push   %ebx
  80094e:	8b 45 08             	mov    0x8(%ebp),%eax
  800951:	8b 5d 0c             	mov    0xc(%ebp),%ebx
  800954:	ba 00 00 00 00       	mov    $0x0,%edx
	char *ret;

	ret = dst;
	while ((*dst++ = *src++) != '\0')
  800959:	0f b6 0c 13          	movzbl (%ebx,%edx,1),%ecx
  80095d:	88 0c 10             	mov    %cl,(%eax,%edx,1)
  800960:	83 c2 01             	add    $0x1,%edx
  800963:	84 c9                	test   %cl,%cl
  800965:	75 f2                	jne    800959 <strcpy+0xf>
		/* do nothing */;
	return ret;
}
  800967:	5b                   	pop    %ebx
  800968:	5d                   	pop    %ebp
  800969:	c3                   	ret    

0080096a <strncpy>:

char *
strncpy(char *dst, const char *src, size_t size) {
  80096a:	55                   	push   %ebp
  80096b:	89 e5                	mov    %esp,%ebp
  80096d:	56                   	push   %esi
  80096e:	53                   	push   %ebx
  80096f:	8b 45 08             	mov    0x8(%ebp),%eax
  800972:	8b 55 0c             	mov    0xc(%ebp),%edx
  800975:	8b 75 10             	mov    0x10(%ebp),%esi
	size_t i;
	char *ret;

	ret = dst;
	for (i = 0; i < size; i++) {
  800978:	85 f6                	test   %esi,%esi
  80097a:	74 18                	je     800994 <strncpy+0x2a>
  80097c:	b9 00 00 00 00       	mov    $0x0,%ecx
		*dst++ = *src;
  800981:	0f b6 1a             	movzbl (%edx),%ebx
  800984:	88 1c 08             	mov    %bl,(%eax,%ecx,1)
		// If strlen(src) < size, null-pad 'dst' out to 'size' chars
		if (*src != '\0')
			src++;
  800987:	80 3a 01             	cmpb   $0x1,(%edx)
  80098a:	83 da ff             	sbb    $0xffffffff,%edx
strncpy(char *dst, const char *src, size_t size) {
	size_t i;
	char *ret;

	ret = dst;
	for (i = 0; i < size; i++) {
  80098d:	83 c1 01             	add    $0x1,%ecx
  800990:	39 ce                	cmp    %ecx,%esi
  800992:	77 ed                	ja     800981 <strncpy+0x17>
		// If strlen(src) < size, null-pad 'dst' out to 'size' chars
		if (*src != '\0')
			src++;
	}
	return ret;
}
  800994:	5b                   	pop    %ebx
  800995:	5e                   	pop    %esi
  800996:	5d                   	pop    %ebp
  800997:	c3                   	ret    

00800998 <strlcpy>:

size_t
strlcpy(char *dst, const char *src, size_t size)
{
  800998:	55                   	push   %ebp
  800999:	89 e5                	mov    %esp,%ebp
  80099b:	56                   	push   %esi
  80099c:	53                   	push   %ebx
  80099d:	8b 75 08             	mov    0x8(%ebp),%esi
  8009a0:	8b 55 0c             	mov    0xc(%ebp),%edx
  8009a3:	8b 4d 10             	mov    0x10(%ebp),%ecx
	char *dst_in;

	dst_in = dst;
	if (size > 0) {
  8009a6:	89 f0                	mov    %esi,%eax
  8009a8:	85 c9                	test   %ecx,%ecx
  8009aa:	74 27                	je     8009d3 <strlcpy+0x3b>
		while (--size > 0 && *src != '\0')
  8009ac:	83 e9 01             	sub    $0x1,%ecx
  8009af:	74 1d                	je     8009ce <strlcpy+0x36>
  8009b1:	0f b6 1a             	movzbl (%edx),%ebx
  8009b4:	84 db                	test   %bl,%bl
  8009b6:	74 16                	je     8009ce <strlcpy+0x36>
			*dst++ = *src++;
  8009b8:	88 18                	mov    %bl,(%eax)
  8009ba:	83 c0 01             	add    $0x1,%eax
{
	char *dst_in;

	dst_in = dst;
	if (size > 0) {
		while (--size > 0 && *src != '\0')
  8009bd:	83 e9 01             	sub    $0x1,%ecx
  8009c0:	74 0e                	je     8009d0 <strlcpy+0x38>
			*dst++ = *src++;
  8009c2:	83 c2 01             	add    $0x1,%edx
{
	char *dst_in;

	dst_in = dst;
	if (size > 0) {
		while (--size > 0 && *src != '\0')
  8009c5:	0f b6 1a             	movzbl (%edx),%ebx
  8009c8:	84 db                	test   %bl,%bl
  8009ca:	75 ec                	jne    8009b8 <strlcpy+0x20>
  8009cc:	eb 02                	jmp    8009d0 <strlcpy+0x38>
  8009ce:	89 f0                	mov    %esi,%eax
			*dst++ = *src++;
		*dst = '\0';
  8009d0:	c6 00 00             	movb   $0x0,(%eax)
  8009d3:	29 f0                	sub    %esi,%eax
	}
	return dst - dst_in;
}
  8009d5:	5b                   	pop    %ebx
  8009d6:	5e                   	pop    %esi
  8009d7:	5d                   	pop    %ebp
  8009d8:	c3                   	ret    

008009d9 <strcmp>:

int
strcmp(const char *p, const char *q)
{
  8009d9:	55                   	push   %ebp
  8009da:	89 e5                	mov    %esp,%ebp
  8009dc:	8b 4d 08             	mov    0x8(%ebp),%ecx
  8009df:	8b 55 0c             	mov    0xc(%ebp),%edx
	while (*p && *p == *q)
  8009e2:	0f b6 01             	movzbl (%ecx),%eax
  8009e5:	84 c0                	test   %al,%al
  8009e7:	74 15                	je     8009fe <strcmp+0x25>
  8009e9:	3a 02                	cmp    (%edx),%al
  8009eb:	75 11                	jne    8009fe <strcmp+0x25>
		p++, q++;
  8009ed:	83 c1 01             	add    $0x1,%ecx
  8009f0:	83 c2 01             	add    $0x1,%edx
}

int
strcmp(const char *p, const char *q)
{
	while (*p && *p == *q)
  8009f3:	0f b6 01             	movzbl (%ecx),%eax
  8009f6:	84 c0                	test   %al,%al
  8009f8:	74 04                	je     8009fe <strcmp+0x25>
  8009fa:	3a 02                	cmp    (%edx),%al
  8009fc:	74 ef                	je     8009ed <strcmp+0x14>
  8009fe:	0f b6 c0             	movzbl %al,%eax
  800a01:	0f b6 12             	movzbl (%edx),%edx
  800a04:	29 d0                	sub    %edx,%eax
		p++, q++;
	return (int) ((unsigned char) *p - (unsigned char) *q);
}
  800a06:	5d                   	pop    %ebp
  800a07:	c3                   	ret    

00800a08 <strncmp>:

int
strncmp(const char *p, const char *q, size_t n)
{
  800a08:	55                   	push   %ebp
  800a09:	89 e5                	mov    %esp,%ebp
  800a0b:	53                   	push   %ebx
  800a0c:	8b 55 08             	mov    0x8(%ebp),%edx
  800a0f:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  800a12:	8b 45 10             	mov    0x10(%ebp),%eax
	while (n > 0 && *p && *p == *q)
  800a15:	85 c0                	test   %eax,%eax
  800a17:	74 23                	je     800a3c <strncmp+0x34>
  800a19:	0f b6 1a             	movzbl (%edx),%ebx
  800a1c:	84 db                	test   %bl,%bl
  800a1e:	74 24                	je     800a44 <strncmp+0x3c>
  800a20:	3a 19                	cmp    (%ecx),%bl
  800a22:	75 20                	jne    800a44 <strncmp+0x3c>
  800a24:	83 e8 01             	sub    $0x1,%eax
  800a27:	74 13                	je     800a3c <strncmp+0x34>
		n--, p++, q++;
  800a29:	83 c2 01             	add    $0x1,%edx
  800a2c:	83 c1 01             	add    $0x1,%ecx
}

int
strncmp(const char *p, const char *q, size_t n)
{
	while (n > 0 && *p && *p == *q)
  800a2f:	0f b6 1a             	movzbl (%edx),%ebx
  800a32:	84 db                	test   %bl,%bl
  800a34:	74 0e                	je     800a44 <strncmp+0x3c>
  800a36:	3a 19                	cmp    (%ecx),%bl
  800a38:	74 ea                	je     800a24 <strncmp+0x1c>
  800a3a:	eb 08                	jmp    800a44 <strncmp+0x3c>
  800a3c:	b8 00 00 00 00       	mov    $0x0,%eax
		n--, p++, q++;
	if (n == 0)
		return 0;
	else
		return (int) ((unsigned char) *p - (unsigned char) *q);
}
  800a41:	5b                   	pop    %ebx
  800a42:	5d                   	pop    %ebp
  800a43:	c3                   	ret    
	while (n > 0 && *p && *p == *q)
		n--, p++, q++;
	if (n == 0)
		return 0;
	else
		return (int) ((unsigned char) *p - (unsigned char) *q);
  800a44:	0f b6 02             	movzbl (%edx),%eax
  800a47:	0f b6 11             	movzbl (%ecx),%edx
  800a4a:	29 d0                	sub    %edx,%eax
  800a4c:	eb f3                	jmp    800a41 <strncmp+0x39>

00800a4e <strchr>:

// Return a pointer to the first occurrence of 'c' in 's',
// or a null pointer if the string has no 'c'.
char *
strchr(const char *s, char c)
{
  800a4e:	55                   	push   %ebp
  800a4f:	89 e5                	mov    %esp,%ebp
  800a51:	8b 45 08             	mov    0x8(%ebp),%eax
  800a54:	0f b6 4d 0c          	movzbl 0xc(%ebp),%ecx
	for (; *s; s++)
  800a58:	0f b6 10             	movzbl (%eax),%edx
  800a5b:	84 d2                	test   %dl,%dl
  800a5d:	74 15                	je     800a74 <strchr+0x26>
		if (*s == c)
  800a5f:	38 ca                	cmp    %cl,%dl
  800a61:	75 07                	jne    800a6a <strchr+0x1c>
  800a63:	eb 14                	jmp    800a79 <strchr+0x2b>
  800a65:	38 ca                	cmp    %cl,%dl
  800a67:	90                   	nop
  800a68:	74 0f                	je     800a79 <strchr+0x2b>
// Return a pointer to the first occurrence of 'c' in 's',
// or a null pointer if the string has no 'c'.
char *
strchr(const char *s, char c)
{
	for (; *s; s++)
  800a6a:	83 c0 01             	add    $0x1,%eax
  800a6d:	0f b6 10             	movzbl (%eax),%edx
  800a70:	84 d2                	test   %dl,%dl
  800a72:	75 f1                	jne    800a65 <strchr+0x17>
  800a74:	b8 00 00 00 00       	mov    $0x0,%eax
		if (*s == c)
			return (char *) s;
	return 0;
}
  800a79:	5d                   	pop    %ebp
  800a7a:	c3                   	ret    

00800a7b <strfind>:

// Return a pointer to the first occurrence of 'c' in 's',
// or a pointer to the string-ending null character if the string has no 'c'.
char *
strfind(const char *s, char c)
{
  800a7b:	55                   	push   %ebp
  800a7c:	89 e5                	mov    %esp,%ebp
  800a7e:	8b 45 08             	mov    0x8(%ebp),%eax
  800a81:	0f b6 4d 0c          	movzbl 0xc(%ebp),%ecx
	for (; *s; s++)
  800a85:	0f b6 10             	movzbl (%eax),%edx
  800a88:	84 d2                	test   %dl,%dl
  800a8a:	74 18                	je     800aa4 <strfind+0x29>
		if (*s == c)
  800a8c:	38 ca                	cmp    %cl,%dl
  800a8e:	75 0a                	jne    800a9a <strfind+0x1f>
  800a90:	eb 12                	jmp    800aa4 <strfind+0x29>
  800a92:	38 ca                	cmp    %cl,%dl
  800a94:	8d 74 26 00          	lea    0x0(%esi,%eiz,1),%esi
  800a98:	74 0a                	je     800aa4 <strfind+0x29>
// Return a pointer to the first occurrence of 'c' in 's',
// or a pointer to the string-ending null character if the string has no 'c'.
char *
strfind(const char *s, char c)
{
	for (; *s; s++)
  800a9a:	83 c0 01             	add    $0x1,%eax
  800a9d:	0f b6 10             	movzbl (%eax),%edx
  800aa0:	84 d2                	test   %dl,%dl
  800aa2:	75 ee                	jne    800a92 <strfind+0x17>
		if (*s == c)
			break;
	return (char *) s;
}
  800aa4:	5d                   	pop    %ebp
  800aa5:	c3                   	ret    

00800aa6 <memset>:

#if ASM
void *
memset(void *v, int c, size_t n)
{
  800aa6:	55                   	push   %ebp
  800aa7:	89 e5                	mov    %esp,%ebp
  800aa9:	83 ec 0c             	sub    $0xc,%esp
  800aac:	89 1c 24             	mov    %ebx,(%esp)
  800aaf:	89 74 24 04          	mov    %esi,0x4(%esp)
  800ab3:	89 7c 24 08          	mov    %edi,0x8(%esp)
  800ab7:	8b 7d 08             	mov    0x8(%ebp),%edi
  800aba:	8b 45 0c             	mov    0xc(%ebp),%eax
  800abd:	8b 4d 10             	mov    0x10(%ebp),%ecx
	char *p;

	if (n == 0)
  800ac0:	85 c9                	test   %ecx,%ecx
  800ac2:	74 30                	je     800af4 <memset+0x4e>
		return v;
	if ((int)v%4 == 0 && n%4 == 0) {
  800ac4:	f7 c7 03 00 00 00    	test   $0x3,%edi
  800aca:	75 25                	jne    800af1 <memset+0x4b>
  800acc:	f6 c1 03             	test   $0x3,%cl
  800acf:	75 20                	jne    800af1 <memset+0x4b>
		c &= 0xFF;
  800ad1:	0f b6 d0             	movzbl %al,%edx
		c = (c<<24)|(c<<16)|(c<<8)|c;
  800ad4:	89 d3                	mov    %edx,%ebx
  800ad6:	c1 e3 08             	shl    $0x8,%ebx
  800ad9:	89 d6                	mov    %edx,%esi
  800adb:	c1 e6 18             	shl    $0x18,%esi
  800ade:	89 d0                	mov    %edx,%eax
  800ae0:	c1 e0 10             	shl    $0x10,%eax
  800ae3:	09 f0                	or     %esi,%eax
  800ae5:	09 d0                	or     %edx,%eax
		asm volatile("cld; rep stosl\n"
  800ae7:	09 d8                	or     %ebx,%eax
  800ae9:	c1 e9 02             	shr    $0x2,%ecx
  800aec:	fc                   	cld    
  800aed:	f3 ab                	rep stos %eax,%es:(%edi)
{
	char *p;

	if (n == 0)
		return v;
	if ((int)v%4 == 0 && n%4 == 0) {
  800aef:	eb 03                	jmp    800af4 <memset+0x4e>
		c = (c<<24)|(c<<16)|(c<<8)|c;
		asm volatile("cld; rep stosl\n"
			:: "D" (v), "a" (c), "c" (n/4)
			: "cc", "memory");
	} else
		asm volatile("cld; rep stosb\n"
  800af1:	fc                   	cld    
  800af2:	f3 aa                	rep stos %al,%es:(%edi)
			:: "D" (v), "a" (c), "c" (n)
			: "cc", "memory");
	return v;
}
  800af4:	89 f8                	mov    %edi,%eax
  800af6:	8b 1c 24             	mov    (%esp),%ebx
  800af9:	8b 74 24 04          	mov    0x4(%esp),%esi
  800afd:	8b 7c 24 08          	mov    0x8(%esp),%edi
  800b01:	89 ec                	mov    %ebp,%esp
  800b03:	5d                   	pop    %ebp
  800b04:	c3                   	ret    

00800b05 <memmove>:

void *
memmove(void *dst, const void *src, size_t n)
{
  800b05:	55                   	push   %ebp
  800b06:	89 e5                	mov    %esp,%ebp
  800b08:	83 ec 08             	sub    $0x8,%esp
  800b0b:	89 34 24             	mov    %esi,(%esp)
  800b0e:	89 7c 24 04          	mov    %edi,0x4(%esp)
  800b12:	8b 45 08             	mov    0x8(%ebp),%eax
  800b15:	8b 4d 10             	mov    0x10(%ebp),%ecx
	const char *s;
	char *d;
	
	s = src;
  800b18:	8b 75 0c             	mov    0xc(%ebp),%esi
	d = dst;
  800b1b:	89 c7                	mov    %eax,%edi
	if (s < d && s + n > d) {
  800b1d:	39 c6                	cmp    %eax,%esi
  800b1f:	73 35                	jae    800b56 <memmove+0x51>
  800b21:	8d 14 0e             	lea    (%esi,%ecx,1),%edx
  800b24:	39 d0                	cmp    %edx,%eax
  800b26:	73 2e                	jae    800b56 <memmove+0x51>
		s += n;
		d += n;
  800b28:	01 cf                	add    %ecx,%edi
		if ((int)s%4 == 0 && (int)d%4 == 0 && n%4 == 0)
  800b2a:	f6 c2 03             	test   $0x3,%dl
  800b2d:	75 1b                	jne    800b4a <memmove+0x45>
  800b2f:	f7 c7 03 00 00 00    	test   $0x3,%edi
  800b35:	75 13                	jne    800b4a <memmove+0x45>
  800b37:	f6 c1 03             	test   $0x3,%cl
  800b3a:	75 0e                	jne    800b4a <memmove+0x45>
			asm volatile("std; rep movsl\n"
  800b3c:	83 ef 04             	sub    $0x4,%edi
  800b3f:	8d 72 fc             	lea    -0x4(%edx),%esi
  800b42:	c1 e9 02             	shr    $0x2,%ecx
  800b45:	fd                   	std    
  800b46:	f3 a5                	rep movsl %ds:(%esi),%es:(%edi)
	s = src;
	d = dst;
	if (s < d && s + n > d) {
		s += n;
		d += n;
		if ((int)s%4 == 0 && (int)d%4 == 0 && n%4 == 0)
  800b48:	eb 09                	jmp    800b53 <memmove+0x4e>
			asm volatile("std; rep movsl\n"
				:: "D" (d-4), "S" (s-4), "c" (n/4) : "cc", "memory");
		else
			asm volatile("std; rep movsb\n"
  800b4a:	83 ef 01             	sub    $0x1,%edi
  800b4d:	8d 72 ff             	lea    -0x1(%edx),%esi
  800b50:	fd                   	std    
  800b51:	f3 a4                	rep movsb %ds:(%esi),%es:(%edi)
				:: "D" (d-1), "S" (s-1), "c" (n) : "cc", "memory");
		// Some versions of GCC rely on DF being clear
		asm volatile("cld" ::: "cc");
  800b53:	fc                   	cld    
	const char *s;
	char *d;
	
	s = src;
	d = dst;
	if (s < d && s + n > d) {
  800b54:	eb 20                	jmp    800b76 <memmove+0x71>
			asm volatile("std; rep movsb\n"
				:: "D" (d-1), "S" (s-1), "c" (n) : "cc", "memory");
		// Some versions of GCC rely on DF being clear
		asm volatile("cld" ::: "cc");
	} else {
		if ((int)s%4 == 0 && (int)d%4 == 0 && n%4 == 0)
  800b56:	f7 c6 03 00 00 00    	test   $0x3,%esi
  800b5c:	75 15                	jne    800b73 <memmove+0x6e>
  800b5e:	f7 c7 03 00 00 00    	test   $0x3,%edi
  800b64:	75 0d                	jne    800b73 <memmove+0x6e>
  800b66:	f6 c1 03             	test   $0x3,%cl
  800b69:	75 08                	jne    800b73 <memmove+0x6e>
			asm volatile("cld; rep movsl\n"
  800b6b:	c1 e9 02             	shr    $0x2,%ecx
  800b6e:	fc                   	cld    
  800b6f:	f3 a5                	rep movsl %ds:(%esi),%es:(%edi)
			asm volatile("std; rep movsb\n"
				:: "D" (d-1), "S" (s-1), "c" (n) : "cc", "memory");
		// Some versions of GCC rely on DF being clear
		asm volatile("cld" ::: "cc");
	} else {
		if ((int)s%4 == 0 && (int)d%4 == 0 && n%4 == 0)
  800b71:	eb 03                	jmp    800b76 <memmove+0x71>
			asm volatile("cld; rep movsl\n"
				:: "D" (d), "S" (s), "c" (n/4) : "cc", "memory");
		else
			asm volatile("cld; rep movsb\n"
  800b73:	fc                   	cld    
  800b74:	f3 a4                	rep movsb %ds:(%esi),%es:(%edi)
				:: "D" (d), "S" (s), "c" (n) : "cc", "memory");
	}
	return dst;
}
  800b76:	8b 34 24             	mov    (%esp),%esi
  800b79:	8b 7c 24 04          	mov    0x4(%esp),%edi
  800b7d:	89 ec                	mov    %ebp,%esp
  800b7f:	5d                   	pop    %ebp
  800b80:	c3                   	ret    

00800b81 <memcpy>:

/* sigh - gcc emits references to this for structure assignments! */
/* it is *not* prototyped in inc/string.h - do not use directly. */
void *
memcpy(void *dst, void *src, size_t n)
{
  800b81:	55                   	push   %ebp
  800b82:	89 e5                	mov    %esp,%ebp
  800b84:	83 ec 0c             	sub    $0xc,%esp
	return memmove(dst, src, n);
  800b87:	8b 45 10             	mov    0x10(%ebp),%eax
  800b8a:	89 44 24 08          	mov    %eax,0x8(%esp)
  800b8e:	8b 45 0c             	mov    0xc(%ebp),%eax
  800b91:	89 44 24 04          	mov    %eax,0x4(%esp)
  800b95:	8b 45 08             	mov    0x8(%ebp),%eax
  800b98:	89 04 24             	mov    %eax,(%esp)
  800b9b:	e8 65 ff ff ff       	call   800b05 <memmove>
}
  800ba0:	c9                   	leave  
  800ba1:	c3                   	ret    

00800ba2 <memcmp>:

int
memcmp(const void *v1, const void *v2, size_t n)
{
  800ba2:	55                   	push   %ebp
  800ba3:	89 e5                	mov    %esp,%ebp
  800ba5:	57                   	push   %edi
  800ba6:	56                   	push   %esi
  800ba7:	53                   	push   %ebx
  800ba8:	8b 75 08             	mov    0x8(%ebp),%esi
  800bab:	8b 7d 0c             	mov    0xc(%ebp),%edi
  800bae:	8b 4d 10             	mov    0x10(%ebp),%ecx
	const uint8_t *s1 = (const uint8_t *) v1;
	const uint8_t *s2 = (const uint8_t *) v2;

	while (n-- > 0) {
  800bb1:	85 c9                	test   %ecx,%ecx
  800bb3:	74 36                	je     800beb <memcmp+0x49>
		if (*s1 != *s2)
  800bb5:	0f b6 06             	movzbl (%esi),%eax
  800bb8:	0f b6 1f             	movzbl (%edi),%ebx
  800bbb:	38 d8                	cmp    %bl,%al
  800bbd:	74 20                	je     800bdf <memcmp+0x3d>
  800bbf:	eb 14                	jmp    800bd5 <memcmp+0x33>
  800bc1:	0f b6 44 16 01       	movzbl 0x1(%esi,%edx,1),%eax
  800bc6:	0f b6 5c 17 01       	movzbl 0x1(%edi,%edx,1),%ebx
  800bcb:	83 c2 01             	add    $0x1,%edx
  800bce:	83 e9 01             	sub    $0x1,%ecx
  800bd1:	38 d8                	cmp    %bl,%al
  800bd3:	74 12                	je     800be7 <memcmp+0x45>
			return (int) *s1 - (int) *s2;
  800bd5:	0f b6 c0             	movzbl %al,%eax
  800bd8:	0f b6 db             	movzbl %bl,%ebx
  800bdb:	29 d8                	sub    %ebx,%eax
  800bdd:	eb 11                	jmp    800bf0 <memcmp+0x4e>
memcmp(const void *v1, const void *v2, size_t n)
{
	const uint8_t *s1 = (const uint8_t *) v1;
	const uint8_t *s2 = (const uint8_t *) v2;

	while (n-- > 0) {
  800bdf:	83 e9 01             	sub    $0x1,%ecx
  800be2:	ba 00 00 00 00       	mov    $0x0,%edx
  800be7:	85 c9                	test   %ecx,%ecx
  800be9:	75 d6                	jne    800bc1 <memcmp+0x1f>
  800beb:	b8 00 00 00 00       	mov    $0x0,%eax
			return (int) *s1 - (int) *s2;
		s1++, s2++;
	}

	return 0;
}
  800bf0:	5b                   	pop    %ebx
  800bf1:	5e                   	pop    %esi
  800bf2:	5f                   	pop    %edi
  800bf3:	5d                   	pop    %ebp
  800bf4:	c3                   	ret    

00800bf5 <memfind>:

void *
memfind(const void *s, int c, size_t n)
{
  800bf5:	55                   	push   %ebp
  800bf6:	89 e5                	mov    %esp,%ebp
  800bf8:	8b 45 08             	mov    0x8(%ebp),%eax
	const void *ends = (const char *) s + n;
  800bfb:	89 c2                	mov    %eax,%edx
  800bfd:	03 55 10             	add    0x10(%ebp),%edx
	for (; s < ends; s++)
  800c00:	39 d0                	cmp    %edx,%eax
  800c02:	73 15                	jae    800c19 <memfind+0x24>
		if (*(const unsigned char *) s == (unsigned char) c)
  800c04:	0f b6 4d 0c          	movzbl 0xc(%ebp),%ecx
  800c08:	38 08                	cmp    %cl,(%eax)
  800c0a:	75 06                	jne    800c12 <memfind+0x1d>
  800c0c:	eb 0b                	jmp    800c19 <memfind+0x24>
  800c0e:	38 08                	cmp    %cl,(%eax)
  800c10:	74 07                	je     800c19 <memfind+0x24>

void *
memfind(const void *s, int c, size_t n)
{
	const void *ends = (const char *) s + n;
	for (; s < ends; s++)
  800c12:	83 c0 01             	add    $0x1,%eax
  800c15:	39 c2                	cmp    %eax,%edx
  800c17:	77 f5                	ja     800c0e <memfind+0x19>
		if (*(const unsigned char *) s == (unsigned char) c)
			break;
	return (void *) s;
}
  800c19:	5d                   	pop    %ebp
  800c1a:	c3                   	ret    

00800c1b <strtol>:

long
strtol(const char *s, char **endptr, int base)
{
  800c1b:	55                   	push   %ebp
  800c1c:	89 e5                	mov    %esp,%ebp
  800c1e:	57                   	push   %edi
  800c1f:	56                   	push   %esi
  800c20:	53                   	push   %ebx
  800c21:	83 ec 04             	sub    $0x4,%esp
  800c24:	8b 55 08             	mov    0x8(%ebp),%edx
  800c27:	8b 5d 10             	mov    0x10(%ebp),%ebx
	int neg = 0;
	long val = 0;

	// gobble initial whitespace
	while (*s == ' ' || *s == '\t')
  800c2a:	0f b6 02             	movzbl (%edx),%eax
  800c2d:	3c 20                	cmp    $0x20,%al
  800c2f:	74 04                	je     800c35 <strtol+0x1a>
  800c31:	3c 09                	cmp    $0x9,%al
  800c33:	75 0e                	jne    800c43 <strtol+0x28>
		s++;
  800c35:	83 c2 01             	add    $0x1,%edx
{
	int neg = 0;
	long val = 0;

	// gobble initial whitespace
	while (*s == ' ' || *s == '\t')
  800c38:	0f b6 02             	movzbl (%edx),%eax
  800c3b:	3c 20                	cmp    $0x20,%al
  800c3d:	74 f6                	je     800c35 <strtol+0x1a>
  800c3f:	3c 09                	cmp    $0x9,%al
  800c41:	74 f2                	je     800c35 <strtol+0x1a>
		s++;

	// plus/minus sign
	if (*s == '+')
  800c43:	3c 2b                	cmp    $0x2b,%al
  800c45:	75 0c                	jne    800c53 <strtol+0x38>
		s++;
  800c47:	83 c2 01             	add    $0x1,%edx
  800c4a:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
  800c51:	eb 15                	jmp    800c68 <strtol+0x4d>
	else if (*s == '-')
  800c53:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
  800c5a:	3c 2d                	cmp    $0x2d,%al
  800c5c:	75 0a                	jne    800c68 <strtol+0x4d>
		s++, neg = 1;
  800c5e:	83 c2 01             	add    $0x1,%edx
  800c61:	c7 45 f0 01 00 00 00 	movl   $0x1,-0x10(%ebp)

	// hex or octal base prefix
	if ((base == 0 || base == 16) && (s[0] == '0' && s[1] == 'x'))
  800c68:	85 db                	test   %ebx,%ebx
  800c6a:	0f 94 c0             	sete   %al
  800c6d:	74 05                	je     800c74 <strtol+0x59>
  800c6f:	83 fb 10             	cmp    $0x10,%ebx
  800c72:	75 18                	jne    800c8c <strtol+0x71>
  800c74:	80 3a 30             	cmpb   $0x30,(%edx)
  800c77:	75 13                	jne    800c8c <strtol+0x71>
  800c79:	80 7a 01 78          	cmpb   $0x78,0x1(%edx)
  800c7d:	8d 76 00             	lea    0x0(%esi),%esi
  800c80:	75 0a                	jne    800c8c <strtol+0x71>
		s += 2, base = 16;
  800c82:	83 c2 02             	add    $0x2,%edx
  800c85:	bb 10 00 00 00       	mov    $0x10,%ebx
		s++;
	else if (*s == '-')
		s++, neg = 1;

	// hex or octal base prefix
	if ((base == 0 || base == 16) && (s[0] == '0' && s[1] == 'x'))
  800c8a:	eb 15                	jmp    800ca1 <strtol+0x86>
		s += 2, base = 16;
	else if (base == 0 && s[0] == '0')
  800c8c:	84 c0                	test   %al,%al
  800c8e:	66 90                	xchg   %ax,%ax
  800c90:	74 0f                	je     800ca1 <strtol+0x86>
  800c92:	bb 0a 00 00 00       	mov    $0xa,%ebx
  800c97:	80 3a 30             	cmpb   $0x30,(%edx)
  800c9a:	75 05                	jne    800ca1 <strtol+0x86>
		s++, base = 8;
  800c9c:	83 c2 01             	add    $0x1,%edx
  800c9f:	b3 08                	mov    $0x8,%bl
		s++, neg = 1;

	// hex or octal base prefix
	if ((base == 0 || base == 16) && (s[0] == '0' && s[1] == 'x'))
		s += 2, base = 16;
	else if (base == 0 && s[0] == '0')
  800ca1:	b8 00 00 00 00       	mov    $0x0,%eax
  800ca6:	89 de                	mov    %ebx,%esi

	// digits
	while (1) {
		int dig;

		if (*s >= '0' && *s <= '9')
  800ca8:	0f b6 0a             	movzbl (%edx),%ecx
  800cab:	89 cf                	mov    %ecx,%edi
  800cad:	8d 59 d0             	lea    -0x30(%ecx),%ebx
  800cb0:	80 fb 09             	cmp    $0x9,%bl
  800cb3:	77 08                	ja     800cbd <strtol+0xa2>
			dig = *s - '0';
  800cb5:	0f be c9             	movsbl %cl,%ecx
  800cb8:	83 e9 30             	sub    $0x30,%ecx
  800cbb:	eb 1e                	jmp    800cdb <strtol+0xc0>
		else if (*s >= 'a' && *s <= 'z')
  800cbd:	8d 5f 9f             	lea    -0x61(%edi),%ebx
  800cc0:	80 fb 19             	cmp    $0x19,%bl
  800cc3:	77 08                	ja     800ccd <strtol+0xb2>
			dig = *s - 'a' + 10;
  800cc5:	0f be c9             	movsbl %cl,%ecx
  800cc8:	83 e9 57             	sub    $0x57,%ecx
  800ccb:	eb 0e                	jmp    800cdb <strtol+0xc0>
		else if (*s >= 'A' && *s <= 'Z')
  800ccd:	8d 5f bf             	lea    -0x41(%edi),%ebx
  800cd0:	80 fb 19             	cmp    $0x19,%bl
  800cd3:	77 15                	ja     800cea <strtol+0xcf>
			dig = *s - 'A' + 10;
  800cd5:	0f be c9             	movsbl %cl,%ecx
  800cd8:	83 e9 37             	sub    $0x37,%ecx
		else
			break;
		if (dig >= base)
  800cdb:	39 f1                	cmp    %esi,%ecx
  800cdd:	7d 0b                	jge    800cea <strtol+0xcf>
			break;
		s++, val = (val * base) + dig;
  800cdf:	83 c2 01             	add    $0x1,%edx
  800ce2:	0f af c6             	imul   %esi,%eax
  800ce5:	8d 04 01             	lea    (%ecx,%eax,1),%eax
		// we don't properly detect overflow!
	}
  800ce8:	eb be                	jmp    800ca8 <strtol+0x8d>
  800cea:	89 c1                	mov    %eax,%ecx

	if (endptr)
  800cec:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
  800cf0:	74 05                	je     800cf7 <strtol+0xdc>
		*endptr = (char *) s;
  800cf2:	8b 5d 0c             	mov    0xc(%ebp),%ebx
  800cf5:	89 13                	mov    %edx,(%ebx)
	return (neg ? -val : val);
  800cf7:	89 ca                	mov    %ecx,%edx
  800cf9:	f7 da                	neg    %edx
  800cfb:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
  800cff:	0f 45 c2             	cmovne %edx,%eax
}
  800d02:	83 c4 04             	add    $0x4,%esp
  800d05:	5b                   	pop    %ebx
  800d06:	5e                   	pop    %esi
  800d07:	5f                   	pop    %edi
  800d08:	5d                   	pop    %ebp
  800d09:	c3                   	ret    
	...

00800d0c <sys_cgetc>:
	syscall(SYS_cputs, 0, (uint32_t)s, len, 0, 0, 0);
}

int
sys_cgetc(void)
{
  800d0c:	55                   	push   %ebp
  800d0d:	89 e5                	mov    %esp,%ebp
  800d0f:	83 ec 0c             	sub    $0xc,%esp
  800d12:	89 1c 24             	mov    %ebx,(%esp)
  800d15:	89 74 24 04          	mov    %esi,0x4(%esp)
  800d19:	89 7c 24 08          	mov    %edi,0x8(%esp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  800d1d:	ba 00 00 00 00       	mov    $0x0,%edx
  800d22:	b8 01 00 00 00       	mov    $0x1,%eax
  800d27:	89 d1                	mov    %edx,%ecx
  800d29:	89 d3                	mov    %edx,%ebx
  800d2b:	89 d7                	mov    %edx,%edi
  800d2d:	89 d6                	mov    %edx,%esi
  800d2f:	cd 30                	int    $0x30

int
sys_cgetc(void)
{
	return syscall(SYS_cgetc, 0, 0, 0, 0, 0, 0);
}
  800d31:	8b 1c 24             	mov    (%esp),%ebx
  800d34:	8b 74 24 04          	mov    0x4(%esp),%esi
  800d38:	8b 7c 24 08          	mov    0x8(%esp),%edi
  800d3c:	89 ec                	mov    %ebp,%esp
  800d3e:	5d                   	pop    %ebp
  800d3f:	c3                   	ret    

00800d40 <sys_cputs>:
	return ret;
}

void
sys_cputs(const char *s, size_t len)
{
  800d40:	55                   	push   %ebp
  800d41:	89 e5                	mov    %esp,%ebp
  800d43:	83 ec 0c             	sub    $0xc,%esp
  800d46:	89 1c 24             	mov    %ebx,(%esp)
  800d49:	89 74 24 04          	mov    %esi,0x4(%esp)
  800d4d:	89 7c 24 08          	mov    %edi,0x8(%esp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  800d51:	b8 00 00 00 00       	mov    $0x0,%eax
  800d56:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  800d59:	8b 55 08             	mov    0x8(%ebp),%edx
  800d5c:	89 c3                	mov    %eax,%ebx
  800d5e:	89 c7                	mov    %eax,%edi
  800d60:	89 c6                	mov    %eax,%esi
  800d62:	cd 30                	int    $0x30

void
sys_cputs(const char *s, size_t len)
{
	syscall(SYS_cputs, 0, (uint32_t)s, len, 0, 0, 0);
}
  800d64:	8b 1c 24             	mov    (%esp),%ebx
  800d67:	8b 74 24 04          	mov    0x4(%esp),%esi
  800d6b:	8b 7c 24 08          	mov    0x8(%esp),%edi
  800d6f:	89 ec                	mov    %ebp,%esp
  800d71:	5d                   	pop    %ebp
  800d72:	c3                   	ret    

00800d73 <sys_ns_recv>:
  return syscall(SYS_ns_send, 0, (uint32_t)pkt, len, 0, 0, 0);
}

int
sys_ns_recv(void *pkt, uint32_t len)
{
  800d73:	55                   	push   %ebp
  800d74:	89 e5                	mov    %esp,%ebp
  800d76:	83 ec 0c             	sub    $0xc,%esp
  800d79:	89 1c 24             	mov    %ebx,(%esp)
  800d7c:	89 74 24 04          	mov    %esi,0x4(%esp)
  800d80:	89 7c 24 08          	mov    %edi,0x8(%esp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  800d84:	bb 00 00 00 00       	mov    $0x0,%ebx
  800d89:	b8 10 00 00 00       	mov    $0x10,%eax
  800d8e:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  800d91:	8b 55 08             	mov    0x8(%ebp),%edx
  800d94:	89 df                	mov    %ebx,%edi
  800d96:	89 de                	mov    %ebx,%esi
  800d98:	cd 30                	int    $0x30

int
sys_ns_recv(void *pkt, uint32_t len)
{
  return syscall(SYS_ns_recv, 0, (uint32_t)pkt, len, 0, 0, 0);
}
  800d9a:	8b 1c 24             	mov    (%esp),%ebx
  800d9d:	8b 74 24 04          	mov    0x4(%esp),%esi
  800da1:	8b 7c 24 08          	mov    0x8(%esp),%edi
  800da5:	89 ec                	mov    %ebp,%esp
  800da7:	5d                   	pop    %ebp
  800da8:	c3                   	ret    

00800da9 <sys_ns_send>:
	return (unsigned int) syscall(SYS_time_msec, 0, 0, 0, 0, 0, 0);
}

int
sys_ns_send(void *pkt, uint32_t len)
{
  800da9:	55                   	push   %ebp
  800daa:	89 e5                	mov    %esp,%ebp
  800dac:	83 ec 0c             	sub    $0xc,%esp
  800daf:	89 1c 24             	mov    %ebx,(%esp)
  800db2:	89 74 24 04          	mov    %esi,0x4(%esp)
  800db6:	89 7c 24 08          	mov    %edi,0x8(%esp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  800dba:	bb 00 00 00 00       	mov    $0x0,%ebx
  800dbf:	b8 0f 00 00 00       	mov    $0xf,%eax
  800dc4:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  800dc7:	8b 55 08             	mov    0x8(%ebp),%edx
  800dca:	89 df                	mov    %ebx,%edi
  800dcc:	89 de                	mov    %ebx,%esi
  800dce:	cd 30                	int    $0x30

int
sys_ns_send(void *pkt, uint32_t len)
{
  return syscall(SYS_ns_send, 0, (uint32_t)pkt, len, 0, 0, 0);
}
  800dd0:	8b 1c 24             	mov    (%esp),%ebx
  800dd3:	8b 74 24 04          	mov    0x4(%esp),%esi
  800dd7:	8b 7c 24 08          	mov    0x8(%esp),%edi
  800ddb:	89 ec                	mov    %ebp,%esp
  800ddd:	5d                   	pop    %ebp
  800dde:	c3                   	ret    

00800ddf <sys_time_msec>:
	return syscall(SYS_ipc_recv, 1, (uint32_t)dstva, 0, 0, 0, 0);
}

unsigned int
sys_time_msec(void)
{
  800ddf:	55                   	push   %ebp
  800de0:	89 e5                	mov    %esp,%ebp
  800de2:	83 ec 0c             	sub    $0xc,%esp
  800de5:	89 1c 24             	mov    %ebx,(%esp)
  800de8:	89 74 24 04          	mov    %esi,0x4(%esp)
  800dec:	89 7c 24 08          	mov    %edi,0x8(%esp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  800df0:	ba 00 00 00 00       	mov    $0x0,%edx
  800df5:	b8 0e 00 00 00       	mov    $0xe,%eax
  800dfa:	89 d1                	mov    %edx,%ecx
  800dfc:	89 d3                	mov    %edx,%ebx
  800dfe:	89 d7                	mov    %edx,%edi
  800e00:	89 d6                	mov    %edx,%esi
  800e02:	cd 30                	int    $0x30

unsigned int
sys_time_msec(void)
{
	return (unsigned int) syscall(SYS_time_msec, 0, 0, 0, 0, 0, 0);
}
  800e04:	8b 1c 24             	mov    (%esp),%ebx
  800e07:	8b 74 24 04          	mov    0x4(%esp),%esi
  800e0b:	8b 7c 24 08          	mov    0x8(%esp),%edi
  800e0f:	89 ec                	mov    %ebp,%esp
  800e11:	5d                   	pop    %ebp
  800e12:	c3                   	ret    

00800e13 <sys_ipc_recv>:
	return syscall(SYS_ipc_try_send, 1, envid, value, (uint32_t) srcva, perm, 0);
}

int
sys_ipc_recv(void *dstva)
{
  800e13:	55                   	push   %ebp
  800e14:	89 e5                	mov    %esp,%ebp
  800e16:	83 ec 38             	sub    $0x38,%esp
  800e19:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  800e1c:	89 75 f8             	mov    %esi,-0x8(%ebp)
  800e1f:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  800e22:	b9 00 00 00 00       	mov    $0x0,%ecx
  800e27:	b8 0d 00 00 00       	mov    $0xd,%eax
  800e2c:	8b 55 08             	mov    0x8(%ebp),%edx
  800e2f:	89 cb                	mov    %ecx,%ebx
  800e31:	89 cf                	mov    %ecx,%edi
  800e33:	89 ce                	mov    %ecx,%esi
  800e35:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  800e37:	85 c0                	test   %eax,%eax
  800e39:	7e 28                	jle    800e63 <sys_ipc_recv+0x50>
		panic("syscall %d returned %d (> 0)", num, ret);
  800e3b:	89 44 24 10          	mov    %eax,0x10(%esp)
  800e3f:	c7 44 24 0c 0d 00 00 	movl   $0xd,0xc(%esp)
  800e46:	00 
  800e47:	c7 44 24 08 eb 30 80 	movl   $0x8030eb,0x8(%esp)
  800e4e:	00 
  800e4f:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  800e56:	00 
  800e57:	c7 04 24 08 31 80 00 	movl   $0x803108,(%esp)
  800e5e:	e8 4d f3 ff ff       	call   8001b0 <_panic>

int
sys_ipc_recv(void *dstva)
{
	return syscall(SYS_ipc_recv, 1, (uint32_t)dstva, 0, 0, 0, 0);
}
  800e63:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  800e66:	8b 75 f8             	mov    -0x8(%ebp),%esi
  800e69:	8b 7d fc             	mov    -0x4(%ebp),%edi
  800e6c:	89 ec                	mov    %ebp,%esp
  800e6e:	5d                   	pop    %ebp
  800e6f:	c3                   	ret    

00800e70 <sys_ipc_try_send>:
	return syscall(SYS_env_set_pgfault_upcall, 1, envid, (uint32_t) upcall, 0, 0, 0);
}

int
sys_ipc_try_send(envid_t envid, uint32_t value, void *srcva, int perm)
{
  800e70:	55                   	push   %ebp
  800e71:	89 e5                	mov    %esp,%ebp
  800e73:	83 ec 38             	sub    $0x38,%esp
  800e76:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  800e79:	89 75 f8             	mov    %esi,-0x8(%ebp)
  800e7c:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  800e7f:	be 00 00 00 00       	mov    $0x0,%esi
  800e84:	b8 0c 00 00 00       	mov    $0xc,%eax
  800e89:	8b 7d 14             	mov    0x14(%ebp),%edi
  800e8c:	8b 5d 10             	mov    0x10(%ebp),%ebx
  800e8f:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  800e92:	8b 55 08             	mov    0x8(%ebp),%edx
  800e95:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  800e97:	85 c0                	test   %eax,%eax
  800e99:	7e 28                	jle    800ec3 <sys_ipc_try_send+0x53>
		panic("syscall %d returned %d (> 0)", num, ret);
  800e9b:	89 44 24 10          	mov    %eax,0x10(%esp)
  800e9f:	c7 44 24 0c 0c 00 00 	movl   $0xc,0xc(%esp)
  800ea6:	00 
  800ea7:	c7 44 24 08 eb 30 80 	movl   $0x8030eb,0x8(%esp)
  800eae:	00 
  800eaf:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  800eb6:	00 
  800eb7:	c7 04 24 08 31 80 00 	movl   $0x803108,(%esp)
  800ebe:	e8 ed f2 ff ff       	call   8001b0 <_panic>

int
sys_ipc_try_send(envid_t envid, uint32_t value, void *srcva, int perm)
{
	return syscall(SYS_ipc_try_send, 1, envid, value, (uint32_t) srcva, perm, 0);
}
  800ec3:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  800ec6:	8b 75 f8             	mov    -0x8(%ebp),%esi
  800ec9:	8b 7d fc             	mov    -0x4(%ebp),%edi
  800ecc:	89 ec                	mov    %ebp,%esp
  800ece:	5d                   	pop    %ebp
  800ecf:	c3                   	ret    

00800ed0 <sys_env_set_pgfault_upcall>:
	return syscall(SYS_env_set_trapframe, 1, envid, (uint32_t) tf, 0, 0, 0);
}

int
sys_env_set_pgfault_upcall(envid_t envid, void *upcall)
{
  800ed0:	55                   	push   %ebp
  800ed1:	89 e5                	mov    %esp,%ebp
  800ed3:	83 ec 38             	sub    $0x38,%esp
  800ed6:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  800ed9:	89 75 f8             	mov    %esi,-0x8(%ebp)
  800edc:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  800edf:	bb 00 00 00 00       	mov    $0x0,%ebx
  800ee4:	b8 0a 00 00 00       	mov    $0xa,%eax
  800ee9:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  800eec:	8b 55 08             	mov    0x8(%ebp),%edx
  800eef:	89 df                	mov    %ebx,%edi
  800ef1:	89 de                	mov    %ebx,%esi
  800ef3:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  800ef5:	85 c0                	test   %eax,%eax
  800ef7:	7e 28                	jle    800f21 <sys_env_set_pgfault_upcall+0x51>
		panic("syscall %d returned %d (> 0)", num, ret);
  800ef9:	89 44 24 10          	mov    %eax,0x10(%esp)
  800efd:	c7 44 24 0c 0a 00 00 	movl   $0xa,0xc(%esp)
  800f04:	00 
  800f05:	c7 44 24 08 eb 30 80 	movl   $0x8030eb,0x8(%esp)
  800f0c:	00 
  800f0d:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  800f14:	00 
  800f15:	c7 04 24 08 31 80 00 	movl   $0x803108,(%esp)
  800f1c:	e8 8f f2 ff ff       	call   8001b0 <_panic>

int
sys_env_set_pgfault_upcall(envid_t envid, void *upcall)
{
	return syscall(SYS_env_set_pgfault_upcall, 1, envid, (uint32_t) upcall, 0, 0, 0);
}
  800f21:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  800f24:	8b 75 f8             	mov    -0x8(%ebp),%esi
  800f27:	8b 7d fc             	mov    -0x4(%ebp),%edi
  800f2a:	89 ec                	mov    %ebp,%esp
  800f2c:	5d                   	pop    %ebp
  800f2d:	c3                   	ret    

00800f2e <sys_env_set_trapframe>:
	return syscall(SYS_env_set_status, 1, envid, status, 0, 0, 0);
}

int
sys_env_set_trapframe(envid_t envid, struct Trapframe *tf)
{
  800f2e:	55                   	push   %ebp
  800f2f:	89 e5                	mov    %esp,%ebp
  800f31:	83 ec 38             	sub    $0x38,%esp
  800f34:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  800f37:	89 75 f8             	mov    %esi,-0x8(%ebp)
  800f3a:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  800f3d:	bb 00 00 00 00       	mov    $0x0,%ebx
  800f42:	b8 09 00 00 00       	mov    $0x9,%eax
  800f47:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  800f4a:	8b 55 08             	mov    0x8(%ebp),%edx
  800f4d:	89 df                	mov    %ebx,%edi
  800f4f:	89 de                	mov    %ebx,%esi
  800f51:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  800f53:	85 c0                	test   %eax,%eax
  800f55:	7e 28                	jle    800f7f <sys_env_set_trapframe+0x51>
		panic("syscall %d returned %d (> 0)", num, ret);
  800f57:	89 44 24 10          	mov    %eax,0x10(%esp)
  800f5b:	c7 44 24 0c 09 00 00 	movl   $0x9,0xc(%esp)
  800f62:	00 
  800f63:	c7 44 24 08 eb 30 80 	movl   $0x8030eb,0x8(%esp)
  800f6a:	00 
  800f6b:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  800f72:	00 
  800f73:	c7 04 24 08 31 80 00 	movl   $0x803108,(%esp)
  800f7a:	e8 31 f2 ff ff       	call   8001b0 <_panic>

int
sys_env_set_trapframe(envid_t envid, struct Trapframe *tf)
{
	return syscall(SYS_env_set_trapframe, 1, envid, (uint32_t) tf, 0, 0, 0);
}
  800f7f:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  800f82:	8b 75 f8             	mov    -0x8(%ebp),%esi
  800f85:	8b 7d fc             	mov    -0x4(%ebp),%edi
  800f88:	89 ec                	mov    %ebp,%esp
  800f8a:	5d                   	pop    %ebp
  800f8b:	c3                   	ret    

00800f8c <sys_env_set_status>:

// sys_exofork is inlined in lib.h

int
sys_env_set_status(envid_t envid, int status)
{
  800f8c:	55                   	push   %ebp
  800f8d:	89 e5                	mov    %esp,%ebp
  800f8f:	83 ec 38             	sub    $0x38,%esp
  800f92:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  800f95:	89 75 f8             	mov    %esi,-0x8(%ebp)
  800f98:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  800f9b:	bb 00 00 00 00       	mov    $0x0,%ebx
  800fa0:	b8 08 00 00 00       	mov    $0x8,%eax
  800fa5:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  800fa8:	8b 55 08             	mov    0x8(%ebp),%edx
  800fab:	89 df                	mov    %ebx,%edi
  800fad:	89 de                	mov    %ebx,%esi
  800faf:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  800fb1:	85 c0                	test   %eax,%eax
  800fb3:	7e 28                	jle    800fdd <sys_env_set_status+0x51>
		panic("syscall %d returned %d (> 0)", num, ret);
  800fb5:	89 44 24 10          	mov    %eax,0x10(%esp)
  800fb9:	c7 44 24 0c 08 00 00 	movl   $0x8,0xc(%esp)
  800fc0:	00 
  800fc1:	c7 44 24 08 eb 30 80 	movl   $0x8030eb,0x8(%esp)
  800fc8:	00 
  800fc9:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  800fd0:	00 
  800fd1:	c7 04 24 08 31 80 00 	movl   $0x803108,(%esp)
  800fd8:	e8 d3 f1 ff ff       	call   8001b0 <_panic>

int
sys_env_set_status(envid_t envid, int status)
{
	return syscall(SYS_env_set_status, 1, envid, status, 0, 0, 0);
}
  800fdd:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  800fe0:	8b 75 f8             	mov    -0x8(%ebp),%esi
  800fe3:	8b 7d fc             	mov    -0x4(%ebp),%edi
  800fe6:	89 ec                	mov    %ebp,%esp
  800fe8:	5d                   	pop    %ebp
  800fe9:	c3                   	ret    

00800fea <sys_page_unmap>:
	return syscall(SYS_page_map, 1, srcenv, (uint32_t) srcva, dstenv, (uint32_t) dstva, perm);
}

int
sys_page_unmap(envid_t envid, void *va)
{
  800fea:	55                   	push   %ebp
  800feb:	89 e5                	mov    %esp,%ebp
  800fed:	83 ec 38             	sub    $0x38,%esp
  800ff0:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  800ff3:	89 75 f8             	mov    %esi,-0x8(%ebp)
  800ff6:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  800ff9:	bb 00 00 00 00       	mov    $0x0,%ebx
  800ffe:	b8 06 00 00 00       	mov    $0x6,%eax
  801003:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  801006:	8b 55 08             	mov    0x8(%ebp),%edx
  801009:	89 df                	mov    %ebx,%edi
  80100b:	89 de                	mov    %ebx,%esi
  80100d:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  80100f:	85 c0                	test   %eax,%eax
  801011:	7e 28                	jle    80103b <sys_page_unmap+0x51>
		panic("syscall %d returned %d (> 0)", num, ret);
  801013:	89 44 24 10          	mov    %eax,0x10(%esp)
  801017:	c7 44 24 0c 06 00 00 	movl   $0x6,0xc(%esp)
  80101e:	00 
  80101f:	c7 44 24 08 eb 30 80 	movl   $0x8030eb,0x8(%esp)
  801026:	00 
  801027:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  80102e:	00 
  80102f:	c7 04 24 08 31 80 00 	movl   $0x803108,(%esp)
  801036:	e8 75 f1 ff ff       	call   8001b0 <_panic>

int
sys_page_unmap(envid_t envid, void *va)
{
	return syscall(SYS_page_unmap, 1, envid, (uint32_t) va, 0, 0, 0);
}
  80103b:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  80103e:	8b 75 f8             	mov    -0x8(%ebp),%esi
  801041:	8b 7d fc             	mov    -0x4(%ebp),%edi
  801044:	89 ec                	mov    %ebp,%esp
  801046:	5d                   	pop    %ebp
  801047:	c3                   	ret    

00801048 <sys_page_map>:
	return syscall(SYS_page_alloc, 1, envid, (uint32_t) va, perm, 0, 0);
}

int
sys_page_map(envid_t srcenv, void *srcva, envid_t dstenv, void *dstva, int perm)
{
  801048:	55                   	push   %ebp
  801049:	89 e5                	mov    %esp,%ebp
  80104b:	83 ec 38             	sub    $0x38,%esp
  80104e:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  801051:	89 75 f8             	mov    %esi,-0x8(%ebp)
  801054:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  801057:	b8 05 00 00 00       	mov    $0x5,%eax
  80105c:	8b 75 18             	mov    0x18(%ebp),%esi
  80105f:	8b 7d 14             	mov    0x14(%ebp),%edi
  801062:	8b 5d 10             	mov    0x10(%ebp),%ebx
  801065:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  801068:	8b 55 08             	mov    0x8(%ebp),%edx
  80106b:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  80106d:	85 c0                	test   %eax,%eax
  80106f:	7e 28                	jle    801099 <sys_page_map+0x51>
		panic("syscall %d returned %d (> 0)", num, ret);
  801071:	89 44 24 10          	mov    %eax,0x10(%esp)
  801075:	c7 44 24 0c 05 00 00 	movl   $0x5,0xc(%esp)
  80107c:	00 
  80107d:	c7 44 24 08 eb 30 80 	movl   $0x8030eb,0x8(%esp)
  801084:	00 
  801085:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  80108c:	00 
  80108d:	c7 04 24 08 31 80 00 	movl   $0x803108,(%esp)
  801094:	e8 17 f1 ff ff       	call   8001b0 <_panic>

int
sys_page_map(envid_t srcenv, void *srcva, envid_t dstenv, void *dstva, int perm)
{
	return syscall(SYS_page_map, 1, srcenv, (uint32_t) srcva, dstenv, (uint32_t) dstva, perm);
}
  801099:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  80109c:	8b 75 f8             	mov    -0x8(%ebp),%esi
  80109f:	8b 7d fc             	mov    -0x4(%ebp),%edi
  8010a2:	89 ec                	mov    %ebp,%esp
  8010a4:	5d                   	pop    %ebp
  8010a5:	c3                   	ret    

008010a6 <sys_page_alloc>:
	syscall(SYS_yield, 0, 0, 0, 0, 0, 0);
}

int
sys_page_alloc(envid_t envid, void *va, int perm)
{
  8010a6:	55                   	push   %ebp
  8010a7:	89 e5                	mov    %esp,%ebp
  8010a9:	83 ec 38             	sub    $0x38,%esp
  8010ac:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  8010af:	89 75 f8             	mov    %esi,-0x8(%ebp)
  8010b2:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  8010b5:	be 00 00 00 00       	mov    $0x0,%esi
  8010ba:	b8 04 00 00 00       	mov    $0x4,%eax
  8010bf:	8b 5d 10             	mov    0x10(%ebp),%ebx
  8010c2:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  8010c5:	8b 55 08             	mov    0x8(%ebp),%edx
  8010c8:	89 f7                	mov    %esi,%edi
  8010ca:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  8010cc:	85 c0                	test   %eax,%eax
  8010ce:	7e 28                	jle    8010f8 <sys_page_alloc+0x52>
		panic("syscall %d returned %d (> 0)", num, ret);
  8010d0:	89 44 24 10          	mov    %eax,0x10(%esp)
  8010d4:	c7 44 24 0c 04 00 00 	movl   $0x4,0xc(%esp)
  8010db:	00 
  8010dc:	c7 44 24 08 eb 30 80 	movl   $0x8030eb,0x8(%esp)
  8010e3:	00 
  8010e4:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  8010eb:	00 
  8010ec:	c7 04 24 08 31 80 00 	movl   $0x803108,(%esp)
  8010f3:	e8 b8 f0 ff ff       	call   8001b0 <_panic>

int
sys_page_alloc(envid_t envid, void *va, int perm)
{
	return syscall(SYS_page_alloc, 1, envid, (uint32_t) va, perm, 0, 0);
}
  8010f8:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  8010fb:	8b 75 f8             	mov    -0x8(%ebp),%esi
  8010fe:	8b 7d fc             	mov    -0x4(%ebp),%edi
  801101:	89 ec                	mov    %ebp,%esp
  801103:	5d                   	pop    %ebp
  801104:	c3                   	ret    

00801105 <sys_yield>:
	 return syscall(SYS_getenvid, 0, 0, 0, 0, 0, 0);
}

void
sys_yield(void)
{
  801105:	55                   	push   %ebp
  801106:	89 e5                	mov    %esp,%ebp
  801108:	83 ec 0c             	sub    $0xc,%esp
  80110b:	89 1c 24             	mov    %ebx,(%esp)
  80110e:	89 74 24 04          	mov    %esi,0x4(%esp)
  801112:	89 7c 24 08          	mov    %edi,0x8(%esp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  801116:	ba 00 00 00 00       	mov    $0x0,%edx
  80111b:	b8 0b 00 00 00       	mov    $0xb,%eax
  801120:	89 d1                	mov    %edx,%ecx
  801122:	89 d3                	mov    %edx,%ebx
  801124:	89 d7                	mov    %edx,%edi
  801126:	89 d6                	mov    %edx,%esi
  801128:	cd 30                	int    $0x30

void
sys_yield(void)
{
	syscall(SYS_yield, 0, 0, 0, 0, 0, 0);
}
  80112a:	8b 1c 24             	mov    (%esp),%ebx
  80112d:	8b 74 24 04          	mov    0x4(%esp),%esi
  801131:	8b 7c 24 08          	mov    0x8(%esp),%edi
  801135:	89 ec                	mov    %ebp,%esp
  801137:	5d                   	pop    %ebp
  801138:	c3                   	ret    

00801139 <sys_getenvid>:
	return syscall(SYS_env_destroy, 1, envid, 0, 0, 0, 0);
}

envid_t
sys_getenvid(void)
{
  801139:	55                   	push   %ebp
  80113a:	89 e5                	mov    %esp,%ebp
  80113c:	83 ec 0c             	sub    $0xc,%esp
  80113f:	89 1c 24             	mov    %ebx,(%esp)
  801142:	89 74 24 04          	mov    %esi,0x4(%esp)
  801146:	89 7c 24 08          	mov    %edi,0x8(%esp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  80114a:	ba 00 00 00 00       	mov    $0x0,%edx
  80114f:	b8 02 00 00 00       	mov    $0x2,%eax
  801154:	89 d1                	mov    %edx,%ecx
  801156:	89 d3                	mov    %edx,%ebx
  801158:	89 d7                	mov    %edx,%edi
  80115a:	89 d6                	mov    %edx,%esi
  80115c:	cd 30                	int    $0x30

envid_t
sys_getenvid(void)
{
	 return syscall(SYS_getenvid, 0, 0, 0, 0, 0, 0);
}
  80115e:	8b 1c 24             	mov    (%esp),%ebx
  801161:	8b 74 24 04          	mov    0x4(%esp),%esi
  801165:	8b 7c 24 08          	mov    0x8(%esp),%edi
  801169:	89 ec                	mov    %ebp,%esp
  80116b:	5d                   	pop    %ebp
  80116c:	c3                   	ret    

0080116d <sys_env_destroy>:
	return syscall(SYS_cgetc, 0, 0, 0, 0, 0, 0);
}

int
sys_env_destroy(envid_t envid)
{
  80116d:	55                   	push   %ebp
  80116e:	89 e5                	mov    %esp,%ebp
  801170:	83 ec 38             	sub    $0x38,%esp
  801173:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  801176:	89 75 f8             	mov    %esi,-0x8(%ebp)
  801179:	89 7d fc             	mov    %edi,-0x4(%ebp)
	// 
	// The last clause tells the assembler that this can
	// potentially change the condition codes and arbitrary
	// memory locations.

	asm volatile("int %1\n"
  80117c:	b9 00 00 00 00       	mov    $0x0,%ecx
  801181:	b8 03 00 00 00       	mov    $0x3,%eax
  801186:	8b 55 08             	mov    0x8(%ebp),%edx
  801189:	89 cb                	mov    %ecx,%ebx
  80118b:	89 cf                	mov    %ecx,%edi
  80118d:	89 ce                	mov    %ecx,%esi
  80118f:	cd 30                	int    $0x30
		  "b" (a3),
		  "D" (a4),
		  "S" (a5)
		: "cc", "memory");
	
	if(check && ret > 0)
  801191:	85 c0                	test   %eax,%eax
  801193:	7e 28                	jle    8011bd <sys_env_destroy+0x50>
		panic("syscall %d returned %d (> 0)", num, ret);
  801195:	89 44 24 10          	mov    %eax,0x10(%esp)
  801199:	c7 44 24 0c 03 00 00 	movl   $0x3,0xc(%esp)
  8011a0:	00 
  8011a1:	c7 44 24 08 eb 30 80 	movl   $0x8030eb,0x8(%esp)
  8011a8:	00 
  8011a9:	c7 44 24 04 23 00 00 	movl   $0x23,0x4(%esp)
  8011b0:	00 
  8011b1:	c7 04 24 08 31 80 00 	movl   $0x803108,(%esp)
  8011b8:	e8 f3 ef ff ff       	call   8001b0 <_panic>

int
sys_env_destroy(envid_t envid)
{
	return syscall(SYS_env_destroy, 1, envid, 0, 0, 0, 0);
}
  8011bd:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  8011c0:	8b 75 f8             	mov    -0x8(%ebp),%esi
  8011c3:	8b 7d fc             	mov    -0x4(%ebp),%edi
  8011c6:	89 ec                	mov    %ebp,%esp
  8011c8:	5d                   	pop    %ebp
  8011c9:	c3                   	ret    
  8011ca:	00 00                	add    %al,(%eax)
  8011cc:	00 00                	add    %al,(%eax)
	...

008011d0 <sfork>:
}

// Challenge!
int
sfork(void)
{
  8011d0:	55                   	push   %ebp
  8011d1:	89 e5                	mov    %esp,%ebp
  8011d3:	83 ec 18             	sub    $0x18,%esp
	panic("sfork not implemented");
  8011d6:	c7 44 24 08 16 31 80 	movl   $0x803116,0x8(%esp)
  8011dd:	00 
  8011de:	c7 44 24 04 9a 00 00 	movl   $0x9a,0x4(%esp)
  8011e5:	00 
  8011e6:	c7 04 24 2c 31 80 00 	movl   $0x80312c,(%esp)
  8011ed:	e8 be ef ff ff       	call   8001b0 <_panic>

008011f2 <fork>:
//   Neither user exception stack should ever be marked copy-on-write,
//   so you must allocate a new page for the child's user exception stack.
//
envid_t
fork(void)
{
  8011f2:	55                   	push   %ebp
  8011f3:	89 e5                	mov    %esp,%ebp
  8011f5:	57                   	push   %edi
  8011f6:	56                   	push   %esi
  8011f7:	53                   	push   %ebx
  8011f8:	83 ec 3c             	sub    $0x3c,%esp
    int r   = 0;
    int i;
    envid_t childId = 0;
	// LAB 4: Your code here.
    // Setup parent process pgfault handler.
    set_pgfault_handler(pgfault);
  8011fb:	c7 04 24 5c 14 80 00 	movl   $0x80145c,(%esp)
  801202:	e8 2d 18 00 00       	call   802a34 <set_pgfault_handler>
static __inline envid_t sys_exofork(void) __attribute__((always_inline));
static __inline envid_t
sys_exofork(void)
{
	envid_t ret;
	__asm __volatile("int %2"
  801207:	ba 07 00 00 00       	mov    $0x7,%edx
  80120c:	89 d0                	mov    %edx,%eax
  80120e:	cd 30                	int    $0x30
  801210:	89 45 d8             	mov    %eax,-0x28(%ebp)
    childId=sys_exofork();

    if (childId<0) {
  801213:	85 c0                	test   %eax,%eax
  801215:	79 20                	jns    801237 <fork+0x45>
        panic("Parent: sys_exofork. Error: 0x%x\n", childId);
  801217:	89 44 24 0c          	mov    %eax,0xc(%esp)
  80121b:	c7 44 24 08 9c 31 80 	movl   $0x80319c,0x8(%esp)
  801222:	00 
  801223:	c7 44 24 04 7b 00 00 	movl   $0x7b,0x4(%esp)
  80122a:	00 
  80122b:	c7 04 24 2c 31 80 00 	movl   $0x80312c,(%esp)
  801232:	e8 79 ef ff ff       	call   8001b0 <_panic>
    } else if (childId>0) {
  801237:	83 7d d8 00          	cmpl   $0x0,-0x28(%ebp)
  80123b:	0f 8e f3 01 00 00    	jle    801434 <fork+0x242>
      // Setup child process' pgfault handler.
      if ((r=sys_env_set_pgfault_upcall(childId, _pgfault_upcall))) {
  801241:	c7 44 24 04 a4 2a 80 	movl   $0x802aa4,0x4(%esp)
  801248:	00 
  801249:	8b 45 d8             	mov    -0x28(%ebp),%eax
  80124c:	89 04 24             	mov    %eax,(%esp)
  80124f:	e8 7c fc ff ff       	call   800ed0 <sys_env_set_pgfault_upcall>
  801254:	85 c0                	test   %eax,%eax
  801256:	74 20                	je     801278 <fork+0x86>
          panic("Child: sys_env_set_pgfault_upcall. Error: %d\n", r);
  801258:	89 44 24 0c          	mov    %eax,0xc(%esp)
  80125c:	c7 44 24 08 c0 31 80 	movl   $0x8031c0,0x8(%esp)
  801263:	00 
  801264:	c7 44 24 04 7f 00 00 	movl   $0x7f,0x4(%esp)
  80126b:	00 
  80126c:	c7 04 24 2c 31 80 00 	movl   $0x80312c,(%esp)
  801273:	e8 38 ef ff ff       	call   8001b0 <_panic>
      }
      
      // Setup child's Image.
      // Allocate page for child's user exception stack.
      if ((r=sys_page_alloc(childId, (void *)(UXSTACKTOP-PGSIZE), PTE_U|PTE_P|PTE_W))<0) {
  801278:	c7 44 24 08 07 00 00 	movl   $0x7,0x8(%esp)
  80127f:	00 
  801280:	c7 44 24 04 00 f0 bf 	movl   $0xeebff000,0x4(%esp)
  801287:	ee 
  801288:	8b 45 d8             	mov    -0x28(%ebp),%eax
  80128b:	89 04 24             	mov    %eax,(%esp)
  80128e:	e8 13 fe ff ff       	call   8010a6 <sys_page_alloc>
  801293:	85 c0                	test   %eax,%eax
  801295:	79 20                	jns    8012b7 <fork+0xc5>
          panic("Parent: sys_page_alloc. Error: 0x%x\n", r);           
  801297:	89 44 24 0c          	mov    %eax,0xc(%esp)
  80129b:	c7 44 24 08 f0 31 80 	movl   $0x8031f0,0x8(%esp)
  8012a2:	00 
  8012a3:	c7 44 24 04 85 00 00 	movl   $0x85,0x4(%esp)
  8012aa:	00 
  8012ab:	c7 04 24 2c 31 80 00 	movl   $0x80312c,(%esp)
  8012b2:	e8 f9 ee ff ff       	call   8001b0 <_panic>
  8012b7:	be 00 00 80 00       	mov    $0x800000,%esi
  8012bc:	bb 00 00 80 00       	mov    $0x800000,%ebx
      }

      // Copy Parent's address space to child.
      for (i=UTEXT;i<USTACKTOP;i+=PGSIZE)
        if (vpd[VPD(i)]&PTE_P)
  8012c1:	bf 00 d0 7b ef       	mov    $0xef7bd000,%edi
  8012c6:	89 f0                	mov    %esi,%eax
  8012c8:	c1 e8 16             	shr    $0x16,%eax
  8012cb:	8b 04 87             	mov    (%edi,%eax,4),%eax
  8012ce:	a8 01                	test   $0x1,%al
  8012d0:	0f 84 13 01 00 00    	je     8013e9 <fork+0x1f7>
// 
static int
duppage(envid_t envid, unsigned pn)
{
	int r           = 0;
  int perm        = vpt[VPN(pn)]&PTE_USER;
  8012d6:	89 f0                	mov    %esi,%eax
  8012d8:	c1 e8 0c             	shr    $0xc,%eax
  8012db:	8b 04 85 00 00 40 ef 	mov    -0x10c00000(,%eax,4),%eax
  8012e2:	89 45 e4             	mov    %eax,-0x1c(%ebp)
  8012e5:	25 07 0e 00 00       	and    $0xe07,%eax
  8012ea:	89 45 e0             	mov    %eax,-0x20(%ebp)
  envid_t env_id  = sys_getenvid();
  8012ed:	e8 47 fe ff ff       	call   801139 <sys_getenvid>
  8012f2:	89 45 dc             	mov    %eax,-0x24(%ebp)

	// LAB 4: Your code here.
  if ((perm&PTE_P) && (perm&PTE_W || perm&PTE_COW) && (!(perm&PTE_SHARE))) {
  8012f5:	f6 45 e4 01          	testb  $0x1,-0x1c(%ebp)
  8012f9:	0f 84 ea 00 00 00    	je     8013e9 <fork+0x1f7>
  8012ff:	f7 45 e0 02 08 00 00 	testl  $0x802,-0x20(%ebp)
  801306:	0f 84 9d 00 00 00    	je     8013a9 <fork+0x1b7>
  80130c:	f7 45 e0 00 04 00 00 	testl  $0x400,-0x20(%ebp)
  801313:	0f 85 90 00 00 00    	jne    8013a9 <fork+0x1b7>
    perm    &= (~PTE_W);
  801319:	8b 45 e0             	mov    -0x20(%ebp),%eax
  80131c:	83 e0 fd             	and    $0xfffffffd,%eax
    perm    |= PTE_COW;
  80131f:	80 cc 08             	or     $0x8,%ah
  801322:	89 45 e4             	mov    %eax,-0x1c(%ebp)
    
    if ((r=sys_page_map(env_id, (void *)pn, envid, (void *)pn, perm))<0)
  801325:	89 75 e0             	mov    %esi,-0x20(%ebp)
  801328:	89 44 24 10          	mov    %eax,0x10(%esp)
  80132c:	89 74 24 0c          	mov    %esi,0xc(%esp)
  801330:	8b 45 d8             	mov    -0x28(%ebp),%eax
  801333:	89 44 24 08          	mov    %eax,0x8(%esp)
  801337:	89 74 24 04          	mov    %esi,0x4(%esp)
  80133b:	8b 45 dc             	mov    -0x24(%ebp),%eax
  80133e:	89 04 24             	mov    %eax,(%esp)
  801341:	e8 02 fd ff ff       	call   801048 <sys_page_map>
  801346:	85 c0                	test   %eax,%eax
  801348:	79 1b                	jns    801365 <fork+0x173>
      cprintf("[0x%x] Mapping to CHILD: sys_page_map. Address 0x%x. Error: %d\n", env_id, pn, r);
  80134a:	89 44 24 0c          	mov    %eax,0xc(%esp)
  80134e:	89 74 24 08          	mov    %esi,0x8(%esp)
  801352:	8b 45 dc             	mov    -0x24(%ebp),%eax
  801355:	89 44 24 04          	mov    %eax,0x4(%esp)
  801359:	c7 04 24 18 32 80 00 	movl   $0x803218,(%esp)
  801360:	e8 10 ef ff ff       	call   800275 <cprintf>
    // Map permissions back to parent on COW.
    if ((r=sys_page_map(envid, (void *)pn, env_id, (void *)pn, perm))<0)
  801365:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  801368:	89 44 24 10          	mov    %eax,0x10(%esp)
  80136c:	8b 45 e0             	mov    -0x20(%ebp),%eax
  80136f:	89 44 24 0c          	mov    %eax,0xc(%esp)
  801373:	8b 45 dc             	mov    -0x24(%ebp),%eax
  801376:	89 44 24 08          	mov    %eax,0x8(%esp)
  80137a:	8b 45 e0             	mov    -0x20(%ebp),%eax
  80137d:	89 44 24 04          	mov    %eax,0x4(%esp)
  801381:	8b 45 d8             	mov    -0x28(%ebp),%eax
  801384:	89 04 24             	mov    %eax,(%esp)
  801387:	e8 bc fc ff ff       	call   801048 <sys_page_map>
  80138c:	85 c0                	test   %eax,%eax
  80138e:	79 59                	jns    8013e9 <fork+0x1f7>
      cprintf("[0x%x] Mapping to PARENT: sys_page_map. Error: %d\n", env_id, r);
  801390:	89 44 24 08          	mov    %eax,0x8(%esp)
  801394:	8b 45 dc             	mov    -0x24(%ebp),%eax
  801397:	89 44 24 04          	mov    %eax,0x4(%esp)
  80139b:	c7 04 24 58 32 80 00 	movl   $0x803258,(%esp)
  8013a2:	e8 ce ee ff ff       	call   800275 <cprintf>
  8013a7:	eb 40                	jmp    8013e9 <fork+0x1f7>
  } else if (perm&PTE_P){
    if ((r=sys_page_map(env_id, (void *)pn, envid, (void *)pn, perm))<0)
  8013a9:	8b 45 e0             	mov    -0x20(%ebp),%eax
  8013ac:	89 44 24 10          	mov    %eax,0x10(%esp)
  8013b0:	89 74 24 0c          	mov    %esi,0xc(%esp)
  8013b4:	8b 45 d8             	mov    -0x28(%ebp),%eax
  8013b7:	89 44 24 08          	mov    %eax,0x8(%esp)
  8013bb:	89 74 24 04          	mov    %esi,0x4(%esp)
  8013bf:	8b 45 dc             	mov    -0x24(%ebp),%eax
  8013c2:	89 04 24             	mov    %eax,(%esp)
  8013c5:	e8 7e fc ff ff       	call   801048 <sys_page_map>
  8013ca:	85 c0                	test   %eax,%eax
  8013cc:	79 1b                	jns    8013e9 <fork+0x1f7>
      cprintf("[0x%x] Mapping to CHILD: sys_page_map. Address 0x%x. Error: %d\n", env_id, pn, r);
  8013ce:	89 44 24 0c          	mov    %eax,0xc(%esp)
  8013d2:	89 74 24 08          	mov    %esi,0x8(%esp)
  8013d6:	8b 45 dc             	mov    -0x24(%ebp),%eax
  8013d9:	89 44 24 04          	mov    %eax,0x4(%esp)
  8013dd:	c7 04 24 18 32 80 00 	movl   $0x803218,(%esp)
  8013e4:	e8 8c ee ff ff       	call   800275 <cprintf>
      if ((r=sys_page_alloc(childId, (void *)(UXSTACKTOP-PGSIZE), PTE_U|PTE_P|PTE_W))<0) {
          panic("Parent: sys_page_alloc. Error: 0x%x\n", r);           
      }

      // Copy Parent's address space to child.
      for (i=UTEXT;i<USTACKTOP;i+=PGSIZE)
  8013e9:	81 c3 00 10 00 00    	add    $0x1000,%ebx
  8013ef:	89 de                	mov    %ebx,%esi
  8013f1:	81 fb 00 e0 bf ee    	cmp    $0xeebfe000,%ebx
  8013f7:	0f 85 c9 fe ff ff    	jne    8012c6 <fork+0xd4>
        if (vpd[VPD(i)]&PTE_P)
          duppage(childId, i);

      // Set child as runnable.
      if ((r = sys_env_set_status(childId, ENV_RUNNABLE)) < 0)
  8013fd:	c7 44 24 04 01 00 00 	movl   $0x1,0x4(%esp)
  801404:	00 
  801405:	8b 45 d8             	mov    -0x28(%ebp),%eax
  801408:	89 04 24             	mov    %eax,(%esp)
  80140b:	e8 7c fb ff ff       	call   800f8c <sys_env_set_status>
  801410:	85 c0                	test   %eax,%eax
  801412:	79 3d                	jns    801451 <fork+0x25f>
        panic("Parent: sys_env_set_status: %e\n", r);
  801414:	89 44 24 0c          	mov    %eax,0xc(%esp)
  801418:	c7 44 24 08 8c 32 80 	movl   $0x80328c,0x8(%esp)
  80141f:	00 
  801420:	c7 44 24 04 8f 00 00 	movl   $0x8f,0x4(%esp)
  801427:	00 
  801428:	c7 04 24 2c 31 80 00 	movl   $0x80312c,(%esp)
  80142f:	e8 7c ed ff ff       	call   8001b0 <_panic>
    } else if (childId==0) {
  801434:	83 7d d8 00          	cmpl   $0x0,-0x28(%ebp)
  801438:	75 17                	jne    801451 <fork+0x25f>
      env = &envs [ENVX(sys_getenvid())];
  80143a:	e8 fa fc ff ff       	call   801139 <sys_getenvid>
  80143f:	25 ff 03 00 00       	and    $0x3ff,%eax
  801444:	6b c0 7c             	imul   $0x7c,%eax,%eax
  801447:	05 00 00 c0 ee       	add    $0xeec00000,%eax
  80144c:	a3 74 70 80 00       	mov    %eax,0x807074
    }
    return childId;
}
  801451:	8b 45 d8             	mov    -0x28(%ebp),%eax
  801454:	83 c4 3c             	add    $0x3c,%esp
  801457:	5b                   	pop    %ebx
  801458:	5e                   	pop    %esi
  801459:	5f                   	pop    %edi
  80145a:	5d                   	pop    %ebp
  80145b:	c3                   	ret    

0080145c <pgfault>:
// Custom page fault handler - if faulting page is copy-on-write,
// map in our own private writable copy.
//
static void
pgfault(struct UTrapframe *utf)
{
  80145c:	55                   	push   %ebp
  80145d:	89 e5                	mov    %esp,%ebp
  80145f:	57                   	push   %edi
  801460:	56                   	push   %esi
  801461:	53                   	push   %ebx
  801462:	83 ec 3c             	sub    $0x3c,%esp
  void *addr    = (void *) utf->utf_fault_va;
  801465:	8b 45 08             	mov    0x8(%ebp),%eax
  801468:	8b 38                	mov    (%eax),%edi
  uint32_t err  = utf->utf_err;
  80146a:	8b 50 04             	mov    0x4(%eax),%edx
  80146d:	89 55 e4             	mov    %edx,-0x1c(%ebp)
  int r         = 0;
  int perm      = 0;
  void *align   = (void *)((int)addr&(~0xFFF));
  801470:	89 fe                	mov    %edi,%esi
  801472:	81 e6 00 f0 ff ff    	and    $0xfffff000,%esi
  envid_t envid = sys_getenvid();
  801478:	e8 bc fc ff ff       	call   801139 <sys_getenvid>
  80147d:	89 c3                	mov    %eax,%ebx
	// copy-on-write page.  If not, panic.
	// Hint:
	//   Use the read-only page table mappings at vpt
	//   (see <inc/memlayout.h>).

  if ((vpd[VPD(align)]&PTE_P) && (vpt[VPN(align)]&PTE_P))
  80147f:	89 f2                	mov    %esi,%edx
  801481:	89 f0                	mov    %esi,%eax
  801483:	c1 e8 16             	shr    $0x16,%eax
  801486:	8b 04 85 00 d0 7b ef 	mov    -0x10843000(,%eax,4),%eax
  80148d:	a8 01                	test   $0x1,%al
  80148f:	74 3e                	je     8014cf <pgfault+0x73>
  801491:	c1 ea 0c             	shr    $0xc,%edx
  801494:	8b 04 95 00 00 40 ef 	mov    -0x10c00000(,%edx,4),%eax
  80149b:	a8 01                	test   $0x1,%al
  80149d:	74 30                	je     8014cf <pgfault+0x73>
    perm  = vpt[VPN(addr)]&PTE_USER;
  80149f:	c1 ef 0c             	shr    $0xc,%edi
  8014a2:	8b 3c bd 00 00 40 ef 	mov    -0x10c00000(,%edi,4),%edi
	// page to the old page's address.
	// Hint:
	//   You should make three system calls.
	//   No need to explicitly delete the old page's mapping.
	// LAB 4: Your code here.
  perm    &= (~PTE_COW);
  8014a9:	81 e7 07 06 00 00    	and    $0x607,%edi
  perm    |= PTE_W;
  8014af:	83 cf 02             	or     $0x2,%edi
  if (!(r=sys_page_alloc(envid, (void *)PFTEMP, perm))) {
  8014b2:	89 7c 24 08          	mov    %edi,0x8(%esp)
  8014b6:	c7 44 24 04 00 f0 7f 	movl   $0x7ff000,0x4(%esp)
  8014bd:	00 
  8014be:	89 1c 24             	mov    %ebx,(%esp)
  8014c1:	e8 e0 fb ff ff       	call   8010a6 <sys_page_alloc>
  8014c6:	85 c0                	test   %eax,%eax
  8014c8:	74 46                	je     801510 <pgfault+0xb4>
  8014ca:	e9 cd 00 00 00       	jmp    80159c <pgfault+0x140>
	//   (see <inc/memlayout.h>).

  if ((vpd[VPD(align)]&PTE_P) && (vpt[VPN(align)]&PTE_P))
    perm  = vpt[VPN(addr)]&PTE_USER;
  else {
    cprintf("Tryig to acess address: %x eip: %x Err: %x\n", align, utf->utf_eip, err);
  8014cf:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  8014d2:	89 44 24 0c          	mov    %eax,0xc(%esp)
  8014d6:	8b 55 08             	mov    0x8(%ebp),%edx
  8014d9:	8b 42 28             	mov    0x28(%edx),%eax
  8014dc:	89 44 24 08          	mov    %eax,0x8(%esp)
  8014e0:	89 74 24 04          	mov    %esi,0x4(%esp)
  8014e4:	c7 04 24 ac 32 80 00 	movl   $0x8032ac,(%esp)
  8014eb:	e8 85 ed ff ff       	call   800275 <cprintf>
    panic("Go to hell :[%x]\n", envid);
  8014f0:	89 5c 24 0c          	mov    %ebx,0xc(%esp)
  8014f4:	c7 44 24 08 37 31 80 	movl   $0x803137,0x8(%esp)
  8014fb:	00 
  8014fc:	c7 44 24 04 24 00 00 	movl   $0x24,0x4(%esp)
  801503:	00 
  801504:	c7 04 24 2c 31 80 00 	movl   $0x80312c,(%esp)
  80150b:	e8 a0 ec ff ff       	call   8001b0 <_panic>
	//   No need to explicitly delete the old page's mapping.
	// LAB 4: Your code here.
  perm    &= (~PTE_COW);
  perm    |= PTE_W;
  if (!(r=sys_page_alloc(envid, (void *)PFTEMP, perm))) {
    memmove((void *)PFTEMP, align, PGSIZE);
  801510:	c7 44 24 08 00 10 00 	movl   $0x1000,0x8(%esp)
  801517:	00 
  801518:	89 74 24 04          	mov    %esi,0x4(%esp)
  80151c:	c7 04 24 00 f0 7f 00 	movl   $0x7ff000,(%esp)
  801523:	e8 dd f5 ff ff       	call   800b05 <memmove>
    if((r=sys_page_map(envid, (void *)PFTEMP, envid, align, perm)))
  801528:	89 7c 24 10          	mov    %edi,0x10(%esp)
  80152c:	89 74 24 0c          	mov    %esi,0xc(%esp)
  801530:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  801534:	c7 44 24 04 00 f0 7f 	movl   $0x7ff000,0x4(%esp)
  80153b:	00 
  80153c:	89 1c 24             	mov    %ebx,(%esp)
  80153f:	e8 04 fb ff ff       	call   801048 <sys_page_map>
  801544:	85 c0                	test   %eax,%eax
  801546:	74 20                	je     801568 <pgfault+0x10c>
      panic("sys_page_map. Error: 0x%x\n", r);
  801548:	89 44 24 0c          	mov    %eax,0xc(%esp)
  80154c:	c7 44 24 08 49 31 80 	movl   $0x803149,0x8(%esp)
  801553:	00 
  801554:	c7 44 24 04 34 00 00 	movl   $0x34,0x4(%esp)
  80155b:	00 
  80155c:	c7 04 24 2c 31 80 00 	movl   $0x80312c,(%esp)
  801563:	e8 48 ec ff ff       	call   8001b0 <_panic>

    if ((r=sys_page_unmap(envid, (void *)PFTEMP)))
  801568:	c7 44 24 04 00 f0 7f 	movl   $0x7ff000,0x4(%esp)
  80156f:	00 
  801570:	89 1c 24             	mov    %ebx,(%esp)
  801573:	e8 72 fa ff ff       	call   800fea <sys_page_unmap>
  801578:	85 c0                	test   %eax,%eax
  80157a:	74 40                	je     8015bc <pgfault+0x160>
      panic("sys_page_unmap. Error: 0x%x\n", r);
  80157c:	89 44 24 0c          	mov    %eax,0xc(%esp)
  801580:	c7 44 24 08 64 31 80 	movl   $0x803164,0x8(%esp)
  801587:	00 
  801588:	c7 44 24 04 37 00 00 	movl   $0x37,0x4(%esp)
  80158f:	00 
  801590:	c7 04 24 2c 31 80 00 	movl   $0x80312c,(%esp)
  801597:	e8 14 ec ff ff       	call   8001b0 <_panic>
  } else
    panic("sys_page_alloc. Error: %d\n", r);
  80159c:	89 44 24 0c          	mov    %eax,0xc(%esp)
  8015a0:	c7 44 24 08 81 31 80 	movl   $0x803181,0x8(%esp)
  8015a7:	00 
  8015a8:	c7 44 24 04 39 00 00 	movl   $0x39,0x4(%esp)
  8015af:	00 
  8015b0:	c7 04 24 2c 31 80 00 	movl   $0x80312c,(%esp)
  8015b7:	e8 f4 eb ff ff       	call   8001b0 <_panic>
}
  8015bc:	83 c4 3c             	add    $0x3c,%esp
  8015bf:	5b                   	pop    %ebx
  8015c0:	5e                   	pop    %esi
  8015c1:	5f                   	pop    %edi
  8015c2:	5d                   	pop    %ebp
  8015c3:	c3                   	ret    
	...

008015d0 <ipc_send>:
//   Use sys_yield() to be CPU-friendly.
//   If 'pg' is null, pass sys_ipc_recv a value that it will understand
//   as meaning "no page".  (Zero is not the right value.)
void
ipc_send(envid_t to_env, uint32_t val, void *pg, int perm)
{
  8015d0:	55                   	push   %ebp
  8015d1:	89 e5                	mov    %esp,%ebp
  8015d3:	57                   	push   %edi
  8015d4:	56                   	push   %esi
  8015d5:	53                   	push   %ebx
  8015d6:	83 ec 2c             	sub    $0x2c,%esp
  8015d9:	8b 75 08             	mov    0x8(%ebp),%esi
  8015dc:	8b 7d 0c             	mov    0xc(%ebp),%edi
  8015df:	8b 5d 10             	mov    0x10(%ebp),%ebx
  int r   = 0;
  while (1) {
    if ((r=sys_ipc_try_send(to_env, val, (pg==NULL?(void *)UTOP:pg), perm)) == -E_IPC_NOT_RECV)
  8015e2:	85 db                	test   %ebx,%ebx
  8015e4:	b8 00 00 c0 ee       	mov    $0xeec00000,%eax
  8015e9:	0f 45 c3             	cmovne %ebx,%eax
  8015ec:	8b 55 14             	mov    0x14(%ebp),%edx
  8015ef:	89 54 24 0c          	mov    %edx,0xc(%esp)
  8015f3:	89 44 24 08          	mov    %eax,0x8(%esp)
  8015f7:	89 7c 24 04          	mov    %edi,0x4(%esp)
  8015fb:	89 34 24             	mov    %esi,(%esp)
  8015fe:	e8 6d f8 ff ff       	call   800e70 <sys_ipc_try_send>
  801603:	83 f8 f9             	cmp    $0xfffffff9,%eax
  801606:	75 0a                	jne    801612 <ipc_send+0x42>
      sys_yield();
  801608:	e8 f8 fa ff ff       	call   801105 <sys_yield>
    else if (r < 0)
      panic("ipc_send to [%x] failed. Error: %x\n", to_env, r);
    else
      return;
  }
  80160d:	8d 76 00             	lea    0x0(%esi),%esi
  801610:	eb d0                	jmp    8015e2 <ipc_send+0x12>
{
  int r   = 0;
  while (1) {
    if ((r=sys_ipc_try_send(to_env, val, (pg==NULL?(void *)UTOP:pg), perm)) == -E_IPC_NOT_RECV)
      sys_yield();
    else if (r < 0)
  801612:	85 c0                	test   %eax,%eax
  801614:	79 24                	jns    80163a <ipc_send+0x6a>
      panic("ipc_send to [%x] failed. Error: %x\n", to_env, r);
  801616:	89 44 24 10          	mov    %eax,0x10(%esp)
  80161a:	89 74 24 0c          	mov    %esi,0xc(%esp)
  80161e:	c7 44 24 08 d8 32 80 	movl   $0x8032d8,0x8(%esp)
  801625:	00 
  801626:	c7 44 24 04 36 00 00 	movl   $0x36,0x4(%esp)
  80162d:	00 
  80162e:	c7 04 24 fc 32 80 00 	movl   $0x8032fc,(%esp)
  801635:	e8 76 eb ff ff       	call   8001b0 <_panic>
    else
      return;
  }
}
  80163a:	83 c4 2c             	add    $0x2c,%esp
  80163d:	5b                   	pop    %ebx
  80163e:	5e                   	pop    %esi
  80163f:	5f                   	pop    %edi
  801640:	5d                   	pop    %ebp
  801641:	c3                   	ret    

00801642 <ipc_recv>:
//   If 'pg' is null, pass sys_ipc_recv a value that it will understand
//   as meaning "no page".  (Zero is not the right value, since that's
//   a perfectly valid place to map a page.)
int32_t
ipc_recv(envid_t *from_env_store, void *pg, int *perm_store)
{
  801642:	55                   	push   %ebp
  801643:	89 e5                	mov    %esp,%ebp
  801645:	56                   	push   %esi
  801646:	53                   	push   %ebx
  801647:	83 ec 10             	sub    $0x10,%esp
  80164a:	8b 5d 08             	mov    0x8(%ebp),%ebx
  80164d:	8b 45 0c             	mov    0xc(%ebp),%eax
  801650:	8b 75 10             	mov    0x10(%ebp),%esi
  int r;
  if ((r=sys_ipc_recv((pg==NULL?(void *)UTOP:pg)))<0)
  801653:	85 c0                	test   %eax,%eax
  801655:	ba 00 00 c0 ee       	mov    $0xeec00000,%edx
  80165a:	0f 44 c2             	cmove  %edx,%eax
  80165d:	89 04 24             	mov    %eax,(%esp)
  801660:	e8 ae f7 ff ff       	call   800e13 <sys_ipc_recv>
  801665:	85 c0                	test   %eax,%eax
  801667:	78 24                	js     80168d <ipc_recv+0x4b>
    return r;

  if (from_env_store)
  801669:	85 db                	test   %ebx,%ebx
  80166b:	74 0a                	je     801677 <ipc_recv+0x35>
    *from_env_store = env->env_ipc_from;
  80166d:	a1 74 70 80 00       	mov    0x807074,%eax
  801672:	8b 40 74             	mov    0x74(%eax),%eax
  801675:	89 03                	mov    %eax,(%ebx)

  if (perm_store)
  801677:	85 f6                	test   %esi,%esi
  801679:	74 0a                	je     801685 <ipc_recv+0x43>
    *perm_store     = env->env_ipc_perm;
  80167b:	a1 74 70 80 00       	mov    0x807074,%eax
  801680:	8b 40 78             	mov    0x78(%eax),%eax
  801683:	89 06                	mov    %eax,(%esi)

  return env->env_ipc_value;
  801685:	a1 74 70 80 00       	mov    0x807074,%eax
  80168a:	8b 40 70             	mov    0x70(%eax),%eax
}
  80168d:	83 c4 10             	add    $0x10,%esp
  801690:	5b                   	pop    %ebx
  801691:	5e                   	pop    %esi
  801692:	5d                   	pop    %ebp
  801693:	c3                   	ret    
	...

008016a0 <fd2num>:
// File descriptor manipulators
// --------------------------------------------------------------

int
fd2num(struct Fd *fd)
{
  8016a0:	55                   	push   %ebp
  8016a1:	89 e5                	mov    %esp,%ebp
  8016a3:	8b 45 08             	mov    0x8(%ebp),%eax
  8016a6:	05 00 00 00 30       	add    $0x30000000,%eax
  8016ab:	c1 e8 0c             	shr    $0xc,%eax
	return ((uintptr_t) fd - FDTABLE) / PGSIZE;
}
  8016ae:	5d                   	pop    %ebp
  8016af:	c3                   	ret    

008016b0 <fd2data>:

char*
fd2data(struct Fd *fd)
{
  8016b0:	55                   	push   %ebp
  8016b1:	89 e5                	mov    %esp,%ebp
  8016b3:	83 ec 04             	sub    $0x4,%esp
	return INDEX2DATA(fd2num(fd));
  8016b6:	8b 45 08             	mov    0x8(%ebp),%eax
  8016b9:	89 04 24             	mov    %eax,(%esp)
  8016bc:	e8 df ff ff ff       	call   8016a0 <fd2num>
  8016c1:	05 20 00 0d 00       	add    $0xd0020,%eax
  8016c6:	c1 e0 0c             	shl    $0xc,%eax
}
  8016c9:	c9                   	leave  
  8016ca:	c3                   	ret    

008016cb <fd_alloc>:
// Returns 0 on success, < 0 on error.  Errors are:
//	-E_MAX_FD: no more file descriptors
// On error, *fd_store is set to 0.
int
fd_alloc(struct Fd **fd_store)
{
  8016cb:	55                   	push   %ebp
  8016cc:	89 e5                	mov    %esp,%ebp
  8016ce:	57                   	push   %edi
  8016cf:	56                   	push   %esi
  8016d0:	53                   	push   %ebx
  8016d1:	8b 7d 08             	mov    0x8(%ebp),%edi
	int i;
	struct Fd *fd;

	for (i = 0; i < MAXFD; i++) {
		fd = INDEX2FD(i);
		if ((vpd[PDX(fd)] & PTE_P) == 0 || (vpt[VPN(fd)] & PTE_P) == 0) {
  8016d4:	a1 00 dd 7b ef       	mov    0xef7bdd00,%eax
  8016d9:	a8 01                	test   $0x1,%al
  8016db:	74 36                	je     801713 <fd_alloc+0x48>
  8016dd:	a1 00 00 74 ef       	mov    0xef740000,%eax
  8016e2:	a8 01                	test   $0x1,%al
  8016e4:	74 2d                	je     801713 <fd_alloc+0x48>
  8016e6:	b8 00 10 00 d0       	mov    $0xd0001000,%eax
  8016eb:	b9 00 d0 7b ef       	mov    $0xef7bd000,%ecx
  8016f0:	be 00 00 40 ef       	mov    $0xef400000,%esi
  8016f5:	89 c3                	mov    %eax,%ebx
  8016f7:	89 c2                	mov    %eax,%edx
  8016f9:	c1 ea 16             	shr    $0x16,%edx
  8016fc:	8b 14 91             	mov    (%ecx,%edx,4),%edx
  8016ff:	f6 c2 01             	test   $0x1,%dl
  801702:	74 14                	je     801718 <fd_alloc+0x4d>
  801704:	89 c2                	mov    %eax,%edx
  801706:	c1 ea 0c             	shr    $0xc,%edx
  801709:	8b 14 96             	mov    (%esi,%edx,4),%edx
  80170c:	f6 c2 01             	test   $0x1,%dl
  80170f:	75 10                	jne    801721 <fd_alloc+0x56>
  801711:	eb 05                	jmp    801718 <fd_alloc+0x4d>
  801713:	bb 00 00 00 d0       	mov    $0xd0000000,%ebx
			*fd_store = fd;
  801718:	89 1f                	mov    %ebx,(%edi)
  80171a:	b8 00 00 00 00       	mov    $0x0,%eax
			return 0;
  80171f:	eb 17                	jmp    801738 <fd_alloc+0x6d>
  801721:	05 00 10 00 00       	add    $0x1000,%eax
fd_alloc(struct Fd **fd_store)
{
	int i;
	struct Fd *fd;

	for (i = 0; i < MAXFD; i++) {
  801726:	3d 00 00 02 d0       	cmp    $0xd0020000,%eax
  80172b:	75 c8                	jne    8016f5 <fd_alloc+0x2a>
		if ((vpd[PDX(fd)] & PTE_P) == 0 || (vpt[VPN(fd)] & PTE_P) == 0) {
			*fd_store = fd;
			return 0;
		}
	}
	*fd_store = 0;
  80172d:	c7 07 00 00 00 00    	movl   $0x0,(%edi)
  801733:	b8 f6 ff ff ff       	mov    $0xfffffff6,%eax
	return -E_MAX_OPEN;
}
  801738:	5b                   	pop    %ebx
  801739:	5e                   	pop    %esi
  80173a:	5f                   	pop    %edi
  80173b:	5d                   	pop    %ebp
  80173c:	c3                   	ret    

0080173d <fd_lookup>:
// Returns 0 on success (the page is in range and mapped), < 0 on error.
// Errors are:
//	-E_INVAL: fdnum was either not in range or not mapped.
int
fd_lookup(int fdnum, struct Fd **fd_store)
{
  80173d:	55                   	push   %ebp
  80173e:	89 e5                	mov    %esp,%ebp
	struct Fd *fd=NULL;

	if (fdnum < 0 || fdnum >= MAXFD) {
  801740:	8b 45 08             	mov    0x8(%ebp),%eax
  801743:	83 f8 1f             	cmp    $0x1f,%eax
  801746:	77 36                	ja     80177e <fd_lookup+0x41>
		if (debug)
			cprintf("[%08x] bad fd %d\n", env->env_id, fd);
		return -E_INVAL;
	}
	fd = INDEX2FD(fdnum);
  801748:	05 00 00 0d 00       	add    $0xd0000,%eax
  80174d:	c1 e0 0c             	shl    $0xc,%eax
	if (!(vpd[PDX(fd)] & PTE_P) || !(vpt[VPN(fd)] & PTE_P)) {
  801750:	89 c2                	mov    %eax,%edx
  801752:	c1 ea 16             	shr    $0x16,%edx
  801755:	8b 14 95 00 d0 7b ef 	mov    -0x10843000(,%edx,4),%edx
  80175c:	f6 c2 01             	test   $0x1,%dl
  80175f:	74 1d                	je     80177e <fd_lookup+0x41>
  801761:	89 c2                	mov    %eax,%edx
  801763:	c1 ea 0c             	shr    $0xc,%edx
  801766:	8b 14 95 00 00 40 ef 	mov    -0x10c00000(,%edx,4),%edx
  80176d:	f6 c2 01             	test   $0x1,%dl
  801770:	74 0c                	je     80177e <fd_lookup+0x41>
		if (debug)
			cprintf("[%08x] closed fd %d\n", env->env_id, fd);
		return -E_INVAL;
	}
	*fd_store = fd;
  801772:	8b 55 0c             	mov    0xc(%ebp),%edx
  801775:	89 02                	mov    %eax,(%edx)
  801777:	b8 00 00 00 00       	mov    $0x0,%eax
	return 0;
  80177c:	eb 05                	jmp    801783 <fd_lookup+0x46>
  80177e:	b8 fd ff ff ff       	mov    $0xfffffffd,%eax
}
  801783:	5d                   	pop    %ebp
  801784:	c3                   	ret    

00801785 <seek>:
	return (*dev->dev_write)(fd, buf, n);
}

int
seek(int fdnum, off_t offset)
{
  801785:	55                   	push   %ebp
  801786:	89 e5                	mov    %esp,%ebp
  801788:	83 ec 18             	sub    $0x18,%esp
	int r;
	struct Fd *fd;
	if ((r = fd_lookup(fdnum, &fd)) < 0)
  80178b:	8d 45 fc             	lea    -0x4(%ebp),%eax
  80178e:	89 44 24 04          	mov    %eax,0x4(%esp)
  801792:	8b 45 08             	mov    0x8(%ebp),%eax
  801795:	89 04 24             	mov    %eax,(%esp)
  801798:	e8 a0 ff ff ff       	call   80173d <fd_lookup>
  80179d:	85 c0                	test   %eax,%eax
  80179f:	78 0e                	js     8017af <seek+0x2a>
		return r;
	fd->fd_offset = offset;
  8017a1:	8b 45 fc             	mov    -0x4(%ebp),%eax
  8017a4:	8b 55 0c             	mov    0xc(%ebp),%edx
  8017a7:	89 50 04             	mov    %edx,0x4(%eax)
  8017aa:	b8 00 00 00 00       	mov    $0x0,%eax
	return 0;
}
  8017af:	c9                   	leave  
  8017b0:	c3                   	ret    

008017b1 <dev_lookup>:
	0
};

int
dev_lookup(int dev_id, struct Dev **dev)
{
  8017b1:	55                   	push   %ebp
  8017b2:	89 e5                	mov    %esp,%ebp
  8017b4:	56                   	push   %esi
  8017b5:	53                   	push   %ebx
  8017b6:	83 ec 10             	sub    $0x10,%esp
  8017b9:	8b 4d 08             	mov    0x8(%ebp),%ecx
  8017bc:	8b 5d 0c             	mov    0xc(%ebp),%ebx
	int i;
	for (i = 0; devtab[i]; i++)
		if (devtab[i]->dev_id == dev_id) {
			*dev = devtab[i];
			return 0;
  8017bf:	ba 00 00 00 00       	mov    $0x0,%edx
int
dev_lookup(int dev_id, struct Dev **dev)
{
	int i;
	for (i = 0; devtab[i]; i++)
		if (devtab[i]->dev_id == dev_id) {
  8017c4:	b8 04 70 80 00       	mov    $0x807004,%eax
  8017c9:	39 0d 04 70 80 00    	cmp    %ecx,0x807004
  8017cf:	75 11                	jne    8017e2 <dev_lookup+0x31>
  8017d1:	eb 04                	jmp    8017d7 <dev_lookup+0x26>
  8017d3:	39 08                	cmp    %ecx,(%eax)
  8017d5:	75 10                	jne    8017e7 <dev_lookup+0x36>
			*dev = devtab[i];
  8017d7:	89 03                	mov    %eax,(%ebx)
  8017d9:	b8 00 00 00 00       	mov    $0x0,%eax
			return 0;
  8017de:	66 90                	xchg   %ax,%ax
  8017e0:	eb 36                	jmp    801818 <dev_lookup+0x67>

int
dev_lookup(int dev_id, struct Dev **dev)
{
	int i;
	for (i = 0; devtab[i]; i++)
  8017e2:	be 84 33 80 00       	mov    $0x803384,%esi
  8017e7:	83 c2 01             	add    $0x1,%edx
  8017ea:	8b 04 96             	mov    (%esi,%edx,4),%eax
  8017ed:	85 c0                	test   %eax,%eax
  8017ef:	75 e2                	jne    8017d3 <dev_lookup+0x22>
		if (devtab[i]->dev_id == dev_id) {
			*dev = devtab[i];
			return 0;
		}
	cprintf("[%08x] unknown device type %d\n", env->env_id, dev_id);
  8017f1:	a1 74 70 80 00       	mov    0x807074,%eax
  8017f6:	8b 40 4c             	mov    0x4c(%eax),%eax
  8017f9:	89 4c 24 08          	mov    %ecx,0x8(%esp)
  8017fd:	89 44 24 04          	mov    %eax,0x4(%esp)
  801801:	c7 04 24 08 33 80 00 	movl   $0x803308,(%esp)
  801808:	e8 68 ea ff ff       	call   800275 <cprintf>
	*dev = 0;
  80180d:	c7 03 00 00 00 00    	movl   $0x0,(%ebx)
  801813:	b8 fd ff ff ff       	mov    $0xfffffffd,%eax
	return -E_INVAL;
}
  801818:	83 c4 10             	add    $0x10,%esp
  80181b:	5b                   	pop    %ebx
  80181c:	5e                   	pop    %esi
  80181d:	5d                   	pop    %ebp
  80181e:	c3                   	ret    

0080181f <fstat>:
	return (*dev->dev_trunc)(fd, newsize);
}

int
fstat(int fdnum, struct Stat *stat)
{
  80181f:	55                   	push   %ebp
  801820:	89 e5                	mov    %esp,%ebp
  801822:	53                   	push   %ebx
  801823:	83 ec 24             	sub    $0x24,%esp
  801826:	8b 5d 0c             	mov    0xc(%ebp),%ebx
	int r;
	struct Dev *dev;
	struct Fd *fd;

	if ((r = fd_lookup(fdnum, &fd)) < 0
  801829:	8d 45 f0             	lea    -0x10(%ebp),%eax
  80182c:	89 44 24 04          	mov    %eax,0x4(%esp)
  801830:	8b 45 08             	mov    0x8(%ebp),%eax
  801833:	89 04 24             	mov    %eax,(%esp)
  801836:	e8 02 ff ff ff       	call   80173d <fd_lookup>
  80183b:	85 c0                	test   %eax,%eax
  80183d:	78 53                	js     801892 <fstat+0x73>
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
  80183f:	8d 45 f4             	lea    -0xc(%ebp),%eax
  801842:	89 44 24 04          	mov    %eax,0x4(%esp)
  801846:	8b 45 f0             	mov    -0x10(%ebp),%eax
  801849:	8b 00                	mov    (%eax),%eax
  80184b:	89 04 24             	mov    %eax,(%esp)
  80184e:	e8 5e ff ff ff       	call   8017b1 <dev_lookup>
{
	int r;
	struct Dev *dev;
	struct Fd *fd;

	if ((r = fd_lookup(fdnum, &fd)) < 0
  801853:	85 c0                	test   %eax,%eax
  801855:	78 3b                	js     801892 <fstat+0x73>
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
		return r;
	if (!dev->dev_stat)
  801857:	b8 f1 ff ff ff       	mov    $0xfffffff1,%eax
  80185c:	8b 55 f4             	mov    -0xc(%ebp),%edx
  80185f:	83 7a 14 00          	cmpl   $0x0,0x14(%edx)
  801863:	74 2d                	je     801892 <fstat+0x73>
		return -E_NOT_SUPP;
	stat->st_name[0] = 0;
  801865:	c6 03 00             	movb   $0x0,(%ebx)
	stat->st_size = 0;
  801868:	c7 83 80 00 00 00 00 	movl   $0x0,0x80(%ebx)
  80186f:	00 00 00 
	stat->st_isdir = 0;
  801872:	c7 83 84 00 00 00 00 	movl   $0x0,0x84(%ebx)
  801879:	00 00 00 
	stat->st_dev = dev;
  80187c:	8b 45 f4             	mov    -0xc(%ebp),%eax
  80187f:	89 83 88 00 00 00    	mov    %eax,0x88(%ebx)
	return (*dev->dev_stat)(fd, stat);
  801885:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  801889:	8b 55 f0             	mov    -0x10(%ebp),%edx
  80188c:	89 14 24             	mov    %edx,(%esp)
  80188f:	ff 50 14             	call   *0x14(%eax)
}
  801892:	83 c4 24             	add    $0x24,%esp
  801895:	5b                   	pop    %ebx
  801896:	5d                   	pop    %ebp
  801897:	c3                   	ret    

00801898 <ftruncate>:
	return 0;
}

int
ftruncate(int fdnum, off_t newsize)
{
  801898:	55                   	push   %ebp
  801899:	89 e5                	mov    %esp,%ebp
  80189b:	53                   	push   %ebx
  80189c:	83 ec 24             	sub    $0x24,%esp
  80189f:	8b 5d 08             	mov    0x8(%ebp),%ebx
	int r;
	struct Dev *dev;
	struct Fd *fd;
	if ((r = fd_lookup(fdnum, &fd)) < 0
  8018a2:	8d 45 f0             	lea    -0x10(%ebp),%eax
  8018a5:	89 44 24 04          	mov    %eax,0x4(%esp)
  8018a9:	89 1c 24             	mov    %ebx,(%esp)
  8018ac:	e8 8c fe ff ff       	call   80173d <fd_lookup>
  8018b1:	85 c0                	test   %eax,%eax
  8018b3:	78 5f                	js     801914 <ftruncate+0x7c>
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
  8018b5:	8d 45 f4             	lea    -0xc(%ebp),%eax
  8018b8:	89 44 24 04          	mov    %eax,0x4(%esp)
  8018bc:	8b 45 f0             	mov    -0x10(%ebp),%eax
  8018bf:	8b 00                	mov    (%eax),%eax
  8018c1:	89 04 24             	mov    %eax,(%esp)
  8018c4:	e8 e8 fe ff ff       	call   8017b1 <dev_lookup>
ftruncate(int fdnum, off_t newsize)
{
	int r;
	struct Dev *dev;
	struct Fd *fd;
	if ((r = fd_lookup(fdnum, &fd)) < 0
  8018c9:	85 c0                	test   %eax,%eax
  8018cb:	78 47                	js     801914 <ftruncate+0x7c>
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
		return r;
	if ((fd->fd_omode & O_ACCMODE) == O_RDONLY) {
  8018cd:	8b 55 f0             	mov    -0x10(%ebp),%edx
  8018d0:	f6 42 08 03          	testb  $0x3,0x8(%edx)
  8018d4:	75 23                	jne    8018f9 <ftruncate+0x61>
		cprintf("[%08x] ftruncate %d -- bad mode\n",
			env->env_id, fdnum); 
  8018d6:	a1 74 70 80 00       	mov    0x807074,%eax
	struct Fd *fd;
	if ((r = fd_lookup(fdnum, &fd)) < 0
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
		return r;
	if ((fd->fd_omode & O_ACCMODE) == O_RDONLY) {
		cprintf("[%08x] ftruncate %d -- bad mode\n",
  8018db:	8b 40 4c             	mov    0x4c(%eax),%eax
  8018de:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  8018e2:	89 44 24 04          	mov    %eax,0x4(%esp)
  8018e6:	c7 04 24 28 33 80 00 	movl   $0x803328,(%esp)
  8018ed:	e8 83 e9 ff ff       	call   800275 <cprintf>
  8018f2:	b8 fd ff ff ff       	mov    $0xfffffffd,%eax
			env->env_id, fdnum); 
		return -E_INVAL;
  8018f7:	eb 1b                	jmp    801914 <ftruncate+0x7c>
	}
	if (!dev->dev_trunc)
  8018f9:	8b 45 f4             	mov    -0xc(%ebp),%eax
  8018fc:	8b 48 18             	mov    0x18(%eax),%ecx
  8018ff:	b8 f1 ff ff ff       	mov    $0xfffffff1,%eax
  801904:	85 c9                	test   %ecx,%ecx
  801906:	74 0c                	je     801914 <ftruncate+0x7c>
		return -E_NOT_SUPP;
	return (*dev->dev_trunc)(fd, newsize);
  801908:	8b 45 0c             	mov    0xc(%ebp),%eax
  80190b:	89 44 24 04          	mov    %eax,0x4(%esp)
  80190f:	89 14 24             	mov    %edx,(%esp)
  801912:	ff d1                	call   *%ecx
}
  801914:	83 c4 24             	add    $0x24,%esp
  801917:	5b                   	pop    %ebx
  801918:	5d                   	pop    %ebp
  801919:	c3                   	ret    

0080191a <write>:
	return tot;
}

ssize_t
write(int fdnum, const void *buf, size_t n)
{
  80191a:	55                   	push   %ebp
  80191b:	89 e5                	mov    %esp,%ebp
  80191d:	53                   	push   %ebx
  80191e:	83 ec 24             	sub    $0x24,%esp
  801921:	8b 5d 08             	mov    0x8(%ebp),%ebx
	int r;
	struct Dev *dev;
	struct Fd *fd;

	if ((r = fd_lookup(fdnum, &fd)) < 0
  801924:	8d 45 f0             	lea    -0x10(%ebp),%eax
  801927:	89 44 24 04          	mov    %eax,0x4(%esp)
  80192b:	89 1c 24             	mov    %ebx,(%esp)
  80192e:	e8 0a fe ff ff       	call   80173d <fd_lookup>
  801933:	85 c0                	test   %eax,%eax
  801935:	78 66                	js     80199d <write+0x83>
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
  801937:	8d 45 f4             	lea    -0xc(%ebp),%eax
  80193a:	89 44 24 04          	mov    %eax,0x4(%esp)
  80193e:	8b 45 f0             	mov    -0x10(%ebp),%eax
  801941:	8b 00                	mov    (%eax),%eax
  801943:	89 04 24             	mov    %eax,(%esp)
  801946:	e8 66 fe ff ff       	call   8017b1 <dev_lookup>
{
	int r;
	struct Dev *dev;
	struct Fd *fd;

	if ((r = fd_lookup(fdnum, &fd)) < 0
  80194b:	85 c0                	test   %eax,%eax
  80194d:	78 4e                	js     80199d <write+0x83>
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
		return r;
	if ((fd->fd_omode & O_ACCMODE) == O_RDONLY) {
  80194f:	8b 55 f0             	mov    -0x10(%ebp),%edx
  801952:	f6 42 08 03          	testb  $0x3,0x8(%edx)
  801956:	75 23                	jne    80197b <write+0x61>
		cprintf("[%08x] write %d -- bad mode\n", env->env_id, fdnum);
  801958:	a1 74 70 80 00       	mov    0x807074,%eax
  80195d:	8b 40 4c             	mov    0x4c(%eax),%eax
  801960:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  801964:	89 44 24 04          	mov    %eax,0x4(%esp)
  801968:	c7 04 24 49 33 80 00 	movl   $0x803349,(%esp)
  80196f:	e8 01 e9 ff ff       	call   800275 <cprintf>
  801974:	b8 fd ff ff ff       	mov    $0xfffffffd,%eax
		return -E_INVAL;
  801979:	eb 22                	jmp    80199d <write+0x83>
	}
	if (debug)
		cprintf("write %d %p %d via dev %s\n",
			fdnum, buf, n, dev->dev_name);
	if (!dev->dev_write)
  80197b:	8b 45 f4             	mov    -0xc(%ebp),%eax
  80197e:	8b 48 0c             	mov    0xc(%eax),%ecx
  801981:	b8 f1 ff ff ff       	mov    $0xfffffff1,%eax
  801986:	85 c9                	test   %ecx,%ecx
  801988:	74 13                	je     80199d <write+0x83>
		return -E_NOT_SUPP;
	return (*dev->dev_write)(fd, buf, n);
  80198a:	8b 45 10             	mov    0x10(%ebp),%eax
  80198d:	89 44 24 08          	mov    %eax,0x8(%esp)
  801991:	8b 45 0c             	mov    0xc(%ebp),%eax
  801994:	89 44 24 04          	mov    %eax,0x4(%esp)
  801998:	89 14 24             	mov    %edx,(%esp)
  80199b:	ff d1                	call   *%ecx
}
  80199d:	83 c4 24             	add    $0x24,%esp
  8019a0:	5b                   	pop    %ebx
  8019a1:	5d                   	pop    %ebp
  8019a2:	c3                   	ret    

008019a3 <read>:
	return r;
}

ssize_t
read(int fdnum, void *buf, size_t n)
{
  8019a3:	55                   	push   %ebp
  8019a4:	89 e5                	mov    %esp,%ebp
  8019a6:	57                   	push   %edi
  8019a7:	56                   	push   %esi
  8019a8:	53                   	push   %ebx
  8019a9:	83 ec 2c             	sub    $0x2c,%esp
  8019ac:	8b 5d 08             	mov    0x8(%ebp),%ebx
  8019af:	8b 75 10             	mov    0x10(%ebp),%esi
	int r;
	int m, tot;
	struct Dev *dev;
	struct Fd *fd;

	if ((r = fd_lookup(fdnum, &fd)) < 0
  8019b2:	8d 45 e0             	lea    -0x20(%ebp),%eax
  8019b5:	89 44 24 04          	mov    %eax,0x4(%esp)
  8019b9:	89 1c 24             	mov    %ebx,(%esp)
  8019bc:	e8 7c fd ff ff       	call   80173d <fd_lookup>
  8019c1:	85 c0                	test   %eax,%eax
  8019c3:	0f 88 b0 00 00 00    	js     801a79 <read+0xd6>
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
  8019c9:	8d 45 e4             	lea    -0x1c(%ebp),%eax
  8019cc:	89 44 24 04          	mov    %eax,0x4(%esp)
  8019d0:	8b 45 e0             	mov    -0x20(%ebp),%eax
  8019d3:	8b 00                	mov    (%eax),%eax
  8019d5:	89 04 24             	mov    %eax,(%esp)
  8019d8:	e8 d4 fd ff ff       	call   8017b1 <dev_lookup>
	int r;
	int m, tot;
	struct Dev *dev;
	struct Fd *fd;

	if ((r = fd_lookup(fdnum, &fd)) < 0
  8019dd:	85 c0                	test   %eax,%eax
  8019df:	0f 88 94 00 00 00    	js     801a79 <read+0xd6>
	    || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0)
		return r;
	if ((fd->fd_omode & O_ACCMODE) == O_WRONLY) {
  8019e5:	8b 45 e0             	mov    -0x20(%ebp),%eax
  8019e8:	8b 40 08             	mov    0x8(%eax),%eax
  8019eb:	83 e0 03             	and    $0x3,%eax
  8019ee:	83 f8 01             	cmp    $0x1,%eax
  8019f1:	75 23                	jne    801a16 <read+0x73>
		cprintf("[%08x] read %d -- bad mode\n", env->env_id, fdnum); 
  8019f3:	a1 74 70 80 00       	mov    0x807074,%eax
  8019f8:	8b 40 4c             	mov    0x4c(%eax),%eax
  8019fb:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  8019ff:	89 44 24 04          	mov    %eax,0x4(%esp)
  801a03:	c7 04 24 66 33 80 00 	movl   $0x803366,(%esp)
  801a0a:	e8 66 e8 ff ff       	call   800275 <cprintf>
  801a0f:	b8 fd ff ff ff       	mov    $0xfffffffd,%eax
		return -E_INVAL;
  801a14:	eb 63                	jmp    801a79 <read+0xd6>
	}
	if (!dev->dev_read)
  801a16:	b8 f1 ff ff ff       	mov    $0xfffffff1,%eax
  801a1b:	8b 55 e4             	mov    -0x1c(%ebp),%edx
  801a1e:	83 7a 08 00          	cmpl   $0x0,0x8(%edx)
  801a22:	74 55                	je     801a79 <read+0xd6>
		return -E_NOT_SUPP;

  for (tot = 0; tot < n; tot += m) {
  801a24:	ba 00 00 00 00       	mov    $0x0,%edx
  801a29:	bb 00 00 00 00       	mov    $0x0,%ebx
  801a2e:	b8 00 00 00 00       	mov    $0x0,%eax
  801a33:	85 f6                	test   %esi,%esi
  801a35:	74 42                	je     801a79 <read+0xd6>
    int count=0;
    if ((n-tot)/PGSIZE == 0)
  801a37:	bf 00 10 00 00       	mov    $0x1000,%edi
  801a3c:	89 f0                	mov    %esi,%eax
  801a3e:	29 d0                	sub    %edx,%eax
  801a40:	89 c1                	mov    %eax,%ecx
  801a42:	81 e1 ff 0f 00 00    	and    $0xfff,%ecx
  801a48:	3d 00 10 00 00       	cmp    $0x1000,%eax
  801a4d:	0f 43 cf             	cmovae %edi,%ecx
      count = (n-tot)%PGSIZE;
    else
      count = PGSIZE;

	  m = (*dev->dev_read)(fd, (char *)buf + tot, count);
  801a50:	89 4c 24 08          	mov    %ecx,0x8(%esp)
  801a54:	03 55 0c             	add    0xc(%ebp),%edx
  801a57:	89 54 24 04          	mov    %edx,0x4(%esp)
  801a5b:	8b 45 e0             	mov    -0x20(%ebp),%eax
  801a5e:	89 04 24             	mov    %eax,(%esp)
  801a61:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  801a64:	ff 50 08             	call   *0x8(%eax)
		if (m < 0)
  801a67:	85 c0                	test   %eax,%eax
  801a69:	78 0e                	js     801a79 <read+0xd6>
			return m;
		if (m == 0)
  801a6b:	85 c0                	test   %eax,%eax
  801a6d:	74 08                	je     801a77 <read+0xd4>
		return -E_INVAL;
	}
	if (!dev->dev_read)
		return -E_NOT_SUPP;

  for (tot = 0; tot < n; tot += m) {
  801a6f:	01 c3                	add    %eax,%ebx
  801a71:	89 da                	mov    %ebx,%edx
  801a73:	39 f3                	cmp    %esi,%ebx
  801a75:	72 c5                	jb     801a3c <read+0x99>
  801a77:	89 d8                	mov    %ebx,%eax
			return m;
		if (m == 0)
			break;
	}
	return tot;
}
  801a79:	83 c4 2c             	add    $0x2c,%esp
  801a7c:	5b                   	pop    %ebx
  801a7d:	5e                   	pop    %esi
  801a7e:	5f                   	pop    %edi
  801a7f:	5d                   	pop    %ebp
  801a80:	c3                   	ret    

00801a81 <readn>:

ssize_t
readn(int fdnum, void *buf, size_t n)
{
  801a81:	55                   	push   %ebp
  801a82:	89 e5                	mov    %esp,%ebp
  801a84:	57                   	push   %edi
  801a85:	56                   	push   %esi
  801a86:	53                   	push   %ebx
  801a87:	83 ec 1c             	sub    $0x1c,%esp
  801a8a:	8b 7d 08             	mov    0x8(%ebp),%edi
  801a8d:	8b 75 10             	mov    0x10(%ebp),%esi
	int m, tot;
  struct Fd *fd = INDEX2FD(fdnum);

	for (tot = 0; tot < n; tot += m) {
  801a90:	ba 00 00 00 00       	mov    $0x0,%edx
  801a95:	bb 00 00 00 00       	mov    $0x0,%ebx
  801a9a:	b8 00 00 00 00       	mov    $0x0,%eax
  801a9f:	85 f6                	test   %esi,%esi
  801aa1:	74 29                	je     801acc <readn+0x4b>
		m = read(fdnum, (char*)buf + tot, n - tot);
  801aa3:	89 f0                	mov    %esi,%eax
  801aa5:	29 d0                	sub    %edx,%eax
  801aa7:	89 44 24 08          	mov    %eax,0x8(%esp)
  801aab:	03 55 0c             	add    0xc(%ebp),%edx
  801aae:	89 54 24 04          	mov    %edx,0x4(%esp)
  801ab2:	89 3c 24             	mov    %edi,(%esp)
  801ab5:	e8 e9 fe ff ff       	call   8019a3 <read>
		if (m < 0)
  801aba:	85 c0                	test   %eax,%eax
  801abc:	78 0e                	js     801acc <readn+0x4b>
			return m;
		if (m == 0)
  801abe:	85 c0                	test   %eax,%eax
  801ac0:	74 08                	je     801aca <readn+0x49>
readn(int fdnum, void *buf, size_t n)
{
	int m, tot;
  struct Fd *fd = INDEX2FD(fdnum);

	for (tot = 0; tot < n; tot += m) {
  801ac2:	01 c3                	add    %eax,%ebx
  801ac4:	89 da                	mov    %ebx,%edx
  801ac6:	39 f3                	cmp    %esi,%ebx
  801ac8:	72 d9                	jb     801aa3 <readn+0x22>
  801aca:	89 d8                	mov    %ebx,%eax
			return m;
		if (m == 0)
			break;
	}
	return tot;
}
  801acc:	83 c4 1c             	add    $0x1c,%esp
  801acf:	5b                   	pop    %ebx
  801ad0:	5e                   	pop    %esi
  801ad1:	5f                   	pop    %edi
  801ad2:	5d                   	pop    %ebp
  801ad3:	c3                   	ret    

00801ad4 <fd_close>:
// If 'must_exist' is 1, then fd_close returns -E_INVAL when passed a
// closed or nonexistent file descriptor.
// Returns 0 on success, < 0 on error.
int
fd_close(struct Fd *fd, bool must_exist)
{
  801ad4:	55                   	push   %ebp
  801ad5:	89 e5                	mov    %esp,%ebp
  801ad7:	83 ec 28             	sub    $0x28,%esp
  801ada:	89 5d f8             	mov    %ebx,-0x8(%ebp)
  801add:	89 75 fc             	mov    %esi,-0x4(%ebp)
  801ae0:	8b 75 08             	mov    0x8(%ebp),%esi
	struct Fd *fd2;
	struct Dev *dev;
	int r;
	if ((r = fd_lookup(fd2num(fd), &fd2)) < 0
  801ae3:	89 34 24             	mov    %esi,(%esp)
  801ae6:	e8 b5 fb ff ff       	call   8016a0 <fd2num>
  801aeb:	8d 55 f4             	lea    -0xc(%ebp),%edx
  801aee:	89 54 24 04          	mov    %edx,0x4(%esp)
  801af2:	89 04 24             	mov    %eax,(%esp)
  801af5:	e8 43 fc ff ff       	call   80173d <fd_lookup>
  801afa:	89 c3                	mov    %eax,%ebx
  801afc:	85 c0                	test   %eax,%eax
  801afe:	78 05                	js     801b05 <fd_close+0x31>
  801b00:	3b 75 f4             	cmp    -0xc(%ebp),%esi
  801b03:	74 0e                	je     801b13 <fd_close+0x3f>
	    || fd != fd2)
		return (must_exist ? r : 0);
  801b05:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
  801b09:	b8 00 00 00 00       	mov    $0x0,%eax
  801b0e:	0f 44 d8             	cmove  %eax,%ebx
  801b11:	eb 3d                	jmp    801b50 <fd_close+0x7c>
	if ((r = dev_lookup(fd->fd_dev_id, &dev)) >= 0) {
  801b13:	8d 45 f0             	lea    -0x10(%ebp),%eax
  801b16:	89 44 24 04          	mov    %eax,0x4(%esp)
  801b1a:	8b 06                	mov    (%esi),%eax
  801b1c:	89 04 24             	mov    %eax,(%esp)
  801b1f:	e8 8d fc ff ff       	call   8017b1 <dev_lookup>
  801b24:	89 c3                	mov    %eax,%ebx
  801b26:	85 c0                	test   %eax,%eax
  801b28:	78 16                	js     801b40 <fd_close+0x6c>
		if (dev->dev_close)
  801b2a:	8b 45 f0             	mov    -0x10(%ebp),%eax
  801b2d:	8b 40 10             	mov    0x10(%eax),%eax
  801b30:	bb 00 00 00 00       	mov    $0x0,%ebx
  801b35:	85 c0                	test   %eax,%eax
  801b37:	74 07                	je     801b40 <fd_close+0x6c>
			r = (*dev->dev_close)(fd);
  801b39:	89 34 24             	mov    %esi,(%esp)
  801b3c:	ff d0                	call   *%eax
  801b3e:	89 c3                	mov    %eax,%ebx
		else
			r = 0;
	}
	// Make sure fd is unmapped.  Might be a no-op if
	// (*dev->dev_close)(fd) already unmapped it.
	(void) sys_page_unmap(0, fd);
  801b40:	89 74 24 04          	mov    %esi,0x4(%esp)
  801b44:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  801b4b:	e8 9a f4 ff ff       	call   800fea <sys_page_unmap>
	return r;
}
  801b50:	89 d8                	mov    %ebx,%eax
  801b52:	8b 5d f8             	mov    -0x8(%ebp),%ebx
  801b55:	8b 75 fc             	mov    -0x4(%ebp),%esi
  801b58:	89 ec                	mov    %ebp,%esp
  801b5a:	5d                   	pop    %ebp
  801b5b:	c3                   	ret    

00801b5c <close>:
	return -E_INVAL;
}

int
close(int fdnum)
{
  801b5c:	55                   	push   %ebp
  801b5d:	89 e5                	mov    %esp,%ebp
  801b5f:	83 ec 28             	sub    $0x28,%esp
	struct Fd *fd;
	int r;

	if ((r = fd_lookup(fdnum, &fd)) < 0)
  801b62:	8d 45 f4             	lea    -0xc(%ebp),%eax
  801b65:	89 44 24 04          	mov    %eax,0x4(%esp)
  801b69:	8b 45 08             	mov    0x8(%ebp),%eax
  801b6c:	89 04 24             	mov    %eax,(%esp)
  801b6f:	e8 c9 fb ff ff       	call   80173d <fd_lookup>
  801b74:	85 c0                	test   %eax,%eax
  801b76:	78 13                	js     801b8b <close+0x2f>
		return r;
	else
		return fd_close(fd, 1);
  801b78:	c7 44 24 04 01 00 00 	movl   $0x1,0x4(%esp)
  801b7f:	00 
  801b80:	8b 45 f4             	mov    -0xc(%ebp),%eax
  801b83:	89 04 24             	mov    %eax,(%esp)
  801b86:	e8 49 ff ff ff       	call   801ad4 <fd_close>
}
  801b8b:	c9                   	leave  
  801b8c:	c3                   	ret    

00801b8d <stat>:
	return (*dev->dev_stat)(fd, stat);
}

int
stat(const char *path, struct Stat *stat)
{
  801b8d:	55                   	push   %ebp
  801b8e:	89 e5                	mov    %esp,%ebp
  801b90:	83 ec 18             	sub    $0x18,%esp
  801b93:	89 5d f8             	mov    %ebx,-0x8(%ebp)
  801b96:	89 75 fc             	mov    %esi,-0x4(%ebp)
	int fd, r;

	if ((fd = open(path, O_RDONLY)) < 0)
  801b99:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
  801ba0:	00 
  801ba1:	8b 45 08             	mov    0x8(%ebp),%eax
  801ba4:	89 04 24             	mov    %eax,(%esp)
  801ba7:	e8 80 03 00 00       	call   801f2c <open>
  801bac:	89 c3                	mov    %eax,%ebx
  801bae:	85 c0                	test   %eax,%eax
  801bb0:	78 1b                	js     801bcd <stat+0x40>
		return fd;
	r = fstat(fd, stat);
  801bb2:	8b 45 0c             	mov    0xc(%ebp),%eax
  801bb5:	89 44 24 04          	mov    %eax,0x4(%esp)
  801bb9:	89 1c 24             	mov    %ebx,(%esp)
  801bbc:	e8 5e fc ff ff       	call   80181f <fstat>
  801bc1:	89 c6                	mov    %eax,%esi
	close(fd);
  801bc3:	89 1c 24             	mov    %ebx,(%esp)
  801bc6:	e8 91 ff ff ff       	call   801b5c <close>
  801bcb:	89 f3                	mov    %esi,%ebx
	return r;
}
  801bcd:	89 d8                	mov    %ebx,%eax
  801bcf:	8b 5d f8             	mov    -0x8(%ebp),%ebx
  801bd2:	8b 75 fc             	mov    -0x4(%ebp),%esi
  801bd5:	89 ec                	mov    %ebp,%esp
  801bd7:	5d                   	pop    %ebp
  801bd8:	c3                   	ret    

00801bd9 <close_all>:
		return fd_close(fd, 1);
}

void
close_all(void)
{
  801bd9:	55                   	push   %ebp
  801bda:	89 e5                	mov    %esp,%ebp
  801bdc:	53                   	push   %ebx
  801bdd:	83 ec 14             	sub    $0x14,%esp
  801be0:	bb 00 00 00 00       	mov    $0x0,%ebx
	int i;
	for (i = 0; i < MAXFD; i++)
		close(i);
  801be5:	89 1c 24             	mov    %ebx,(%esp)
  801be8:	e8 6f ff ff ff       	call   801b5c <close>

void
close_all(void)
{
	int i;
	for (i = 0; i < MAXFD; i++)
  801bed:	83 c3 01             	add    $0x1,%ebx
  801bf0:	83 fb 20             	cmp    $0x20,%ebx
  801bf3:	75 f0                	jne    801be5 <close_all+0xc>
		close(i);
}
  801bf5:	83 c4 14             	add    $0x14,%esp
  801bf8:	5b                   	pop    %ebx
  801bf9:	5d                   	pop    %ebp
  801bfa:	c3                   	ret    

00801bfb <dup>:
// file and the file offset of the other.
// Closes any previously open file descriptor at 'newfdnum'.
// This is implemented using virtual memory tricks (of course!).
int
dup(int oldfdnum, int newfdnum)
{
  801bfb:	55                   	push   %ebp
  801bfc:	89 e5                	mov    %esp,%ebp
  801bfe:	83 ec 58             	sub    $0x58,%esp
  801c01:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  801c04:	89 75 f8             	mov    %esi,-0x8(%ebp)
  801c07:	89 7d fc             	mov    %edi,-0x4(%ebp)
  801c0a:	8b 7d 0c             	mov    0xc(%ebp),%edi
	int r;
	char *ova, *nva;
	pte_t pte;
	struct Fd *oldfd, *newfd;

	if ((r = fd_lookup(oldfdnum, &oldfd)) < 0)
  801c0d:	8d 45 e4             	lea    -0x1c(%ebp),%eax
  801c10:	89 44 24 04          	mov    %eax,0x4(%esp)
  801c14:	8b 45 08             	mov    0x8(%ebp),%eax
  801c17:	89 04 24             	mov    %eax,(%esp)
  801c1a:	e8 1e fb ff ff       	call   80173d <fd_lookup>
  801c1f:	89 c3                	mov    %eax,%ebx
  801c21:	85 c0                	test   %eax,%eax
  801c23:	0f 88 e0 00 00 00    	js     801d09 <dup+0x10e>
		return r;
	close(newfdnum);
  801c29:	89 3c 24             	mov    %edi,(%esp)
  801c2c:	e8 2b ff ff ff       	call   801b5c <close>

	newfd = INDEX2FD(newfdnum);
  801c31:	8d b7 00 00 0d 00    	lea    0xd0000(%edi),%esi
  801c37:	c1 e6 0c             	shl    $0xc,%esi
	ova = fd2data(oldfd);
  801c3a:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  801c3d:	89 04 24             	mov    %eax,(%esp)
  801c40:	e8 6b fa ff ff       	call   8016b0 <fd2data>
  801c45:	89 c3                	mov    %eax,%ebx
	nva = fd2data(newfd);
  801c47:	89 34 24             	mov    %esi,(%esp)
  801c4a:	e8 61 fa ff ff       	call   8016b0 <fd2data>
  801c4f:	89 45 d4             	mov    %eax,-0x2c(%ebp)
	if ((vpd[PDX(ova)] & PTE_P) && (vpt[VPN(ova)] & PTE_P))
  801c52:	89 da                	mov    %ebx,%edx
  801c54:	89 d8                	mov    %ebx,%eax
  801c56:	c1 e8 16             	shr    $0x16,%eax
  801c59:	8b 04 85 00 d0 7b ef 	mov    -0x10843000(,%eax,4),%eax
  801c60:	a8 01                	test   $0x1,%al
  801c62:	74 43                	je     801ca7 <dup+0xac>
  801c64:	c1 ea 0c             	shr    $0xc,%edx
  801c67:	8b 04 95 00 00 40 ef 	mov    -0x10c00000(,%edx,4),%eax
  801c6e:	a8 01                	test   $0x1,%al
  801c70:	74 35                	je     801ca7 <dup+0xac>
		if ((r = sys_page_map(0, ova, 0, nva, (vpt[VPN(ova)]) & PTE_USER)) < 0)
  801c72:	8b 04 95 00 00 40 ef 	mov    -0x10c00000(,%edx,4),%eax
  801c79:	25 07 0e 00 00       	and    $0xe07,%eax
  801c7e:	89 44 24 10          	mov    %eax,0x10(%esp)
  801c82:	8b 45 d4             	mov    -0x2c(%ebp),%eax
  801c85:	89 44 24 0c          	mov    %eax,0xc(%esp)
  801c89:	c7 44 24 08 00 00 00 	movl   $0x0,0x8(%esp)
  801c90:	00 
  801c91:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  801c95:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  801c9c:	e8 a7 f3 ff ff       	call   801048 <sys_page_map>
  801ca1:	89 c3                	mov    %eax,%ebx
  801ca3:	85 c0                	test   %eax,%eax
  801ca5:	78 3f                	js     801ce6 <dup+0xeb>
			goto err;
	if ((r = sys_page_map(0, oldfd, 0, newfd, (vpt[VPN(oldfd)]) & PTE_USER)) < 0)
  801ca7:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  801caa:	89 c2                	mov    %eax,%edx
  801cac:	c1 ea 0c             	shr    $0xc,%edx
  801caf:	8b 14 95 00 00 40 ef 	mov    -0x10c00000(,%edx,4),%edx
  801cb6:	81 e2 07 0e 00 00    	and    $0xe07,%edx
  801cbc:	89 54 24 10          	mov    %edx,0x10(%esp)
  801cc0:	89 74 24 0c          	mov    %esi,0xc(%esp)
  801cc4:	c7 44 24 08 00 00 00 	movl   $0x0,0x8(%esp)
  801ccb:	00 
  801ccc:	89 44 24 04          	mov    %eax,0x4(%esp)
  801cd0:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  801cd7:	e8 6c f3 ff ff       	call   801048 <sys_page_map>
  801cdc:	89 c3                	mov    %eax,%ebx
  801cde:	85 c0                	test   %eax,%eax
  801ce0:	78 04                	js     801ce6 <dup+0xeb>
  801ce2:	89 fb                	mov    %edi,%ebx
  801ce4:	eb 23                	jmp    801d09 <dup+0x10e>
		goto err;

	return newfdnum;
err:
	sys_page_unmap(0, newfd);
  801ce6:	89 74 24 04          	mov    %esi,0x4(%esp)
  801cea:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  801cf1:	e8 f4 f2 ff ff       	call   800fea <sys_page_unmap>
	sys_page_unmap(0, nva);
  801cf6:	8b 45 d4             	mov    -0x2c(%ebp),%eax
  801cf9:	89 44 24 04          	mov    %eax,0x4(%esp)
  801cfd:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  801d04:	e8 e1 f2 ff ff       	call   800fea <sys_page_unmap>
	return r;
}
  801d09:	89 d8                	mov    %ebx,%eax
  801d0b:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  801d0e:	8b 75 f8             	mov    -0x8(%ebp),%esi
  801d11:	8b 7d fc             	mov    -0x4(%ebp),%edi
  801d14:	89 ec                	mov    %ebp,%esp
  801d16:	5d                   	pop    %ebp
  801d17:	c3                   	ret    

00801d18 <fsipc>:
// type: request code, passed as the simple integer IPC value.
// dstva: virtual address at which to receive reply page, 0 if none.
// Returns result from the file server.
static int
fsipc(unsigned type, void *dstva)
{
  801d18:	55                   	push   %ebp
  801d19:	89 e5                	mov    %esp,%ebp
  801d1b:	53                   	push   %ebx
  801d1c:	83 ec 14             	sub    $0x14,%esp
  801d1f:	89 d3                	mov    %edx,%ebx
	if (debug)
		cprintf("[%08x] fsipc %d %08x\n", env->env_id, type, *(uint32_t *)&fsipcbuf);

	ipc_send(envs[1].env_id, type, &fsipcbuf, PTE_P | PTE_W | PTE_U);
  801d21:	8b 15 c8 00 c0 ee    	mov    0xeec000c8,%edx
  801d27:	c7 44 24 0c 07 00 00 	movl   $0x7,0xc(%esp)
  801d2e:	00 
  801d2f:	c7 44 24 08 00 40 80 	movl   $0x804000,0x8(%esp)
  801d36:	00 
  801d37:	89 44 24 04          	mov    %eax,0x4(%esp)
  801d3b:	89 14 24             	mov    %edx,(%esp)
  801d3e:	e8 8d f8 ff ff       	call   8015d0 <ipc_send>
	return ipc_recv(NULL, dstva, NULL);
  801d43:	c7 44 24 08 00 00 00 	movl   $0x0,0x8(%esp)
  801d4a:	00 
  801d4b:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  801d4f:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  801d56:	e8 e7 f8 ff ff       	call   801642 <ipc_recv>
}
  801d5b:	83 c4 14             	add    $0x14,%esp
  801d5e:	5b                   	pop    %ebx
  801d5f:	5d                   	pop    %ebp
  801d60:	c3                   	ret    

00801d61 <devfile_trunc>:
}

// Truncate or extend an open file to 'size' bytes
static int
devfile_trunc(struct Fd *fd, off_t newsize)
{
  801d61:	55                   	push   %ebp
  801d62:	89 e5                	mov    %esp,%ebp
  801d64:	83 ec 08             	sub    $0x8,%esp
	fsipcbuf.set_size.req_fileid = fd->fd_file.id;
  801d67:	8b 45 08             	mov    0x8(%ebp),%eax
  801d6a:	8b 40 0c             	mov    0xc(%eax),%eax
  801d6d:	a3 00 40 80 00       	mov    %eax,0x804000
	fsipcbuf.set_size.req_size = newsize;
  801d72:	8b 45 0c             	mov    0xc(%ebp),%eax
  801d75:	a3 04 40 80 00       	mov    %eax,0x804004
	return fsipc(FSREQ_SET_SIZE, NULL);
  801d7a:	ba 00 00 00 00       	mov    $0x0,%edx
  801d7f:	b8 02 00 00 00       	mov    $0x2,%eax
  801d84:	e8 8f ff ff ff       	call   801d18 <fsipc>
}
  801d89:	c9                   	leave  
  801d8a:	c3                   	ret    

00801d8b <devfile_flush>:
// open, unmapping it is enough to free up server-side resources.
// Other than that, we just have to make sure our changes are flushed
// to disk.
static int
devfile_flush(struct Fd *fd)
{
  801d8b:	55                   	push   %ebp
  801d8c:	89 e5                	mov    %esp,%ebp
  801d8e:	83 ec 08             	sub    $0x8,%esp
	fsipcbuf.flush.req_fileid = fd->fd_file.id;
  801d91:	8b 45 08             	mov    0x8(%ebp),%eax
  801d94:	8b 40 0c             	mov    0xc(%eax),%eax
  801d97:	a3 00 40 80 00       	mov    %eax,0x804000
	return fsipc(FSREQ_FLUSH, NULL);
  801d9c:	ba 00 00 00 00       	mov    $0x0,%edx
  801da1:	b8 06 00 00 00       	mov    $0x6,%eax
  801da6:	e8 6d ff ff ff       	call   801d18 <fsipc>
}
  801dab:	c9                   	leave  
  801dac:	c3                   	ret    

00801dad <sync>:
}

// Synchronize disk with buffer cache
int
sync(void)
{
  801dad:	55                   	push   %ebp
  801dae:	89 e5                	mov    %esp,%ebp
  801db0:	83 ec 08             	sub    $0x8,%esp
	// Ask the file server to update the disk
	// by writing any dirty blocks in the buffer cache.

	return fsipc(FSREQ_SYNC, NULL);
  801db3:	ba 00 00 00 00       	mov    $0x0,%edx
  801db8:	b8 08 00 00 00       	mov    $0x8,%eax
  801dbd:	e8 56 ff ff ff       	call   801d18 <fsipc>
}
  801dc2:	c9                   	leave  
  801dc3:	c3                   	ret    

00801dc4 <devfile_stat>:
    return n;
}

static int
devfile_stat(struct Fd *fd, struct Stat *st)
{
  801dc4:	55                   	push   %ebp
  801dc5:	89 e5                	mov    %esp,%ebp
  801dc7:	53                   	push   %ebx
  801dc8:	83 ec 14             	sub    $0x14,%esp
  801dcb:	8b 5d 0c             	mov    0xc(%ebp),%ebx
	int r;

	fsipcbuf.stat.req_fileid = fd->fd_file.id;
  801dce:	8b 45 08             	mov    0x8(%ebp),%eax
  801dd1:	8b 40 0c             	mov    0xc(%eax),%eax
  801dd4:	a3 00 40 80 00       	mov    %eax,0x804000
	if ((r = fsipc(FSREQ_STAT, NULL)) < 0)
  801dd9:	ba 00 00 00 00       	mov    $0x0,%edx
  801dde:	b8 05 00 00 00       	mov    $0x5,%eax
  801de3:	e8 30 ff ff ff       	call   801d18 <fsipc>
  801de8:	85 c0                	test   %eax,%eax
  801dea:	78 2b                	js     801e17 <devfile_stat+0x53>
		return r;
	strcpy(st->st_name, fsipcbuf.statRet.ret_name);
  801dec:	c7 44 24 04 00 40 80 	movl   $0x804000,0x4(%esp)
  801df3:	00 
  801df4:	89 1c 24             	mov    %ebx,(%esp)
  801df7:	e8 4e eb ff ff       	call   80094a <strcpy>
	st->st_size = fsipcbuf.statRet.ret_size;
  801dfc:	a1 80 40 80 00       	mov    0x804080,%eax
  801e01:	89 83 80 00 00 00    	mov    %eax,0x80(%ebx)
	st->st_isdir = fsipcbuf.statRet.ret_isdir;
  801e07:	a1 84 40 80 00       	mov    0x804084,%eax
  801e0c:	89 83 84 00 00 00    	mov    %eax,0x84(%ebx)
  801e12:	b8 00 00 00 00       	mov    $0x0,%eax
	return 0;
}
  801e17:	83 c4 14             	add    $0x14,%esp
  801e1a:	5b                   	pop    %ebx
  801e1b:	5d                   	pop    %ebp
  801e1c:	c3                   	ret    

00801e1d <devfile_write>:
// Returns:
//	 The number of bytes successfully written.
//	 < 0 on error.
static ssize_t
devfile_write(struct Fd *fd, const void *buf, size_t n)
{
  801e1d:	55                   	push   %ebp
  801e1e:	89 e5                	mov    %esp,%ebp
  801e20:	53                   	push   %ebx
  801e21:	83 ec 14             	sub    $0x14,%esp
  801e24:	8b 45 08             	mov    0x8(%ebp),%eax
  801e27:	8b 55 0c             	mov    0xc(%ebp),%edx
  801e2a:	8b 5d 10             	mov    0x10(%ebp),%ebx
	// careful: fsipcbuf.write.req_buf is only so large, but
	// remember that write is always allowed to write *fewer*
	// bytes than requested.
	// LAB 5: Your code here
    int r;
    if (!fd || !buf || (n>(PGSIZE-sizeof(size_t)-sizeof(int))))
  801e2d:	85 c0                	test   %eax,%eax
  801e2f:	74 44                	je     801e75 <devfile_write+0x58>
  801e31:	85 d2                	test   %edx,%edx
  801e33:	74 40                	je     801e75 <devfile_write+0x58>
  801e35:	81 fb f8 0f 00 00    	cmp    $0xff8,%ebx
  801e3b:	77 38                	ja     801e75 <devfile_write+0x58>
        return -E_INVAL;

    fsipcbuf.write.req_fileid   = fd->fd_file.id;
  801e3d:	8b 40 0c             	mov    0xc(%eax),%eax
  801e40:	a3 00 40 80 00       	mov    %eax,0x804000
    fsipcbuf.write.req_n        = n;
  801e45:	89 1d 04 40 80 00    	mov    %ebx,0x804004
    memmove(fsipcbuf.write.req_buf, buf, n);
  801e4b:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  801e4f:	89 54 24 04          	mov    %edx,0x4(%esp)
  801e53:	c7 04 24 08 40 80 00 	movl   $0x804008,(%esp)
  801e5a:	e8 a6 ec ff ff       	call   800b05 <memmove>
    if ((r=fsipc(FSREQ_WRITE, NULL))<0)
  801e5f:	ba 00 00 00 00       	mov    $0x0,%edx
  801e64:	b8 04 00 00 00       	mov    $0x4,%eax
  801e69:	e8 aa fe ff ff       	call   801d18 <fsipc>
        return r;
    return n;
  801e6e:	85 c0                	test   %eax,%eax
  801e70:	0f 49 c3             	cmovns %ebx,%eax
  801e73:	eb 05                	jmp    801e7a <devfile_write+0x5d>
  801e75:	b8 fd ff ff ff       	mov    $0xfffffffd,%eax
}
  801e7a:	83 c4 14             	add    $0x14,%esp
  801e7d:	5b                   	pop    %ebx
  801e7e:	5d                   	pop    %ebp
  801e7f:	c3                   	ret    

00801e80 <devfile_read>:
// Returns:
// 	The number of bytes successfully read.
// 	< 0 on error.
static ssize_t
devfile_read(struct Fd *fd, void *buf, size_t n)
{
  801e80:	55                   	push   %ebp
  801e81:	89 e5                	mov    %esp,%ebp
  801e83:	83 ec 18             	sub    $0x18,%esp
  801e86:	89 5d f8             	mov    %ebx,-0x8(%ebp)
  801e89:	89 75 fc             	mov    %esi,-0x4(%ebp)
  801e8c:	8b 45 08             	mov    0x8(%ebp),%eax
  801e8f:	8b 75 0c             	mov    0xc(%ebp),%esi
	// filling fsipcbuf.read with the request arguments.  The
	// bytes read will be written back to fsipcbuf by the file
	// system server.
	// LAB 5: Your code here
  int r;
  if (!fd || !buf)
  801e92:	85 c0                	test   %eax,%eax
  801e94:	74 04                	je     801e9a <devfile_read+0x1a>
  801e96:	85 f6                	test   %esi,%esi
  801e98:	75 07                	jne    801ea1 <devfile_read+0x21>
  801e9a:	bb fd ff ff ff       	mov    $0xfffffffd,%ebx
  801e9f:	eb 39                	jmp    801eda <devfile_read+0x5a>
    return -E_INVAL;

  fsipcbuf.read.req_fileid    = fd->fd_file.id;
  801ea1:	8b 40 0c             	mov    0xc(%eax),%eax
  801ea4:	a3 00 40 80 00       	mov    %eax,0x804000
  fsipcbuf.read.req_n         = n;
  801ea9:	8b 45 10             	mov    0x10(%ebp),%eax
  801eac:	a3 04 40 80 00       	mov    %eax,0x804004
  if ((r=fsipc(FSREQ_READ, NULL))<0)
  801eb1:	ba 00 00 00 00       	mov    $0x0,%edx
  801eb6:	b8 03 00 00 00       	mov    $0x3,%eax
  801ebb:	e8 58 fe ff ff       	call   801d18 <fsipc>
  801ec0:	89 c3                	mov    %eax,%ebx
  801ec2:	85 c0                	test   %eax,%eax
  801ec4:	78 14                	js     801eda <devfile_read+0x5a>
    return r;

  memmove(buf, fsipcbuf.readRet.ret_buf, r);
  801ec6:	89 44 24 08          	mov    %eax,0x8(%esp)
  801eca:	c7 44 24 04 00 40 80 	movl   $0x804000,0x4(%esp)
  801ed1:	00 
  801ed2:	89 34 24             	mov    %esi,(%esp)
  801ed5:	e8 2b ec ff ff       	call   800b05 <memmove>
  return r;
}
  801eda:	89 d8                	mov    %ebx,%eax
  801edc:	8b 5d f8             	mov    -0x8(%ebp),%ebx
  801edf:	8b 75 fc             	mov    -0x4(%ebp),%esi
  801ee2:	89 ec                	mov    %ebp,%esp
  801ee4:	5d                   	pop    %ebp
  801ee5:	c3                   	ret    

00801ee6 <remove>:
}

// Delete a file
int
remove(const char *path)
{
  801ee6:	55                   	push   %ebp
  801ee7:	89 e5                	mov    %esp,%ebp
  801ee9:	53                   	push   %ebx
  801eea:	83 ec 14             	sub    $0x14,%esp
  801eed:	8b 5d 08             	mov    0x8(%ebp),%ebx
	if (strlen(path) >= MAXPATHLEN)
  801ef0:	89 1c 24             	mov    %ebx,(%esp)
  801ef3:	e8 08 ea ff ff       	call   800900 <strlen>
  801ef8:	89 c2                	mov    %eax,%edx
  801efa:	b8 f4 ff ff ff       	mov    $0xfffffff4,%eax
  801eff:	81 fa ff 03 00 00    	cmp    $0x3ff,%edx
  801f05:	7f 1f                	jg     801f26 <remove+0x40>
		return -E_BAD_PATH;
	strcpy(fsipcbuf.remove.req_path, path);
  801f07:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  801f0b:	c7 04 24 00 40 80 00 	movl   $0x804000,(%esp)
  801f12:	e8 33 ea ff ff       	call   80094a <strcpy>
	return fsipc(FSREQ_REMOVE, NULL);
  801f17:	ba 00 00 00 00       	mov    $0x0,%edx
  801f1c:	b8 07 00 00 00       	mov    $0x7,%eax
  801f21:	e8 f2 fd ff ff       	call   801d18 <fsipc>
}
  801f26:	83 c4 14             	add    $0x14,%esp
  801f29:	5b                   	pop    %ebx
  801f2a:	5d                   	pop    %ebp
  801f2b:	c3                   	ret    

00801f2c <open>:
// 	The file descriptor index on success
// 	-E_BAD_PATH if the path is too long (>= MAXPATHLEN)
// 	< 0 for other errors.
int
open(const char *path, int mode)
{
  801f2c:	55                   	push   %ebp
  801f2d:	89 e5                	mov    %esp,%ebp
  801f2f:	83 ec 28             	sub    $0x28,%esp
  801f32:	89 5d f8             	mov    %ebx,-0x8(%ebp)
  801f35:	89 75 fc             	mov    %esi,-0x4(%ebp)
  801f38:	8b 75 08             	mov    0x8(%ebp),%esi
	// Return the file descriptor index.
	// If any step after fd_alloc fails, use fd_close to free the
  struct Fd *f    = NULL;
  int r   = 0;

  if (!path)
  801f3b:	bb fd ff ff ff       	mov    $0xfffffffd,%ebx
  801f40:	85 f6                	test   %esi,%esi
  801f42:	74 65                	je     801fa9 <open+0x7d>
	// (fd_alloc does not allocate a page, it just returns an
	// unused fd address.  Do you need to allocate a page?)
	//
	// Return the file descriptor index.
	// If any step after fd_alloc fails, use fd_close to free the
  struct Fd *f    = NULL;
  801f44:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
  int r   = 0;

  if (!path)
    return -E_INVAL;
  if((r=fd_alloc(&f))<0)
  801f4b:	8d 45 f4             	lea    -0xc(%ebp),%eax
  801f4e:	89 04 24             	mov    %eax,(%esp)
  801f51:	e8 75 f7 ff ff       	call   8016cb <fd_alloc>
  801f56:	89 c3                	mov    %eax,%ebx
  801f58:	85 c0                	test   %eax,%eax
  801f5a:	78 4d                	js     801fa9 <open+0x7d>
    return r;

	strcpy(fsipcbuf.open.req_path, path);
  801f5c:	89 74 24 04          	mov    %esi,0x4(%esp)
  801f60:	c7 04 24 00 40 80 00 	movl   $0x804000,(%esp)
  801f67:	e8 de e9 ff ff       	call   80094a <strcpy>
	fsipcbuf.open.req_omode = mode;
  801f6c:	8b 45 0c             	mov    0xc(%ebp),%eax
  801f6f:	a3 00 44 80 00       	mov    %eax,0x804400

  if ((r=fsipc(FSREQ_OPEN, f))<0) {
  801f74:	8b 55 f4             	mov    -0xc(%ebp),%edx
  801f77:	b8 01 00 00 00       	mov    $0x1,%eax
  801f7c:	e8 97 fd ff ff       	call   801d18 <fsipc>
  801f81:	89 c3                	mov    %eax,%ebx
  801f83:	85 c0                	test   %eax,%eax
  801f85:	79 15                	jns    801f9c <open+0x70>
    fd_close(f, 0);
  801f87:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
  801f8e:	00 
  801f8f:	8b 45 f4             	mov    -0xc(%ebp),%eax
  801f92:	89 04 24             	mov    %eax,(%esp)
  801f95:	e8 3a fb ff ff       	call   801ad4 <fd_close>
    return r;
  801f9a:	eb 0d                	jmp    801fa9 <open+0x7d>
  }
  return fd2num(f);
  801f9c:	8b 45 f4             	mov    -0xc(%ebp),%eax
  801f9f:	89 04 24             	mov    %eax,(%esp)
  801fa2:	e8 f9 f6 ff ff       	call   8016a0 <fd2num>
  801fa7:	89 c3                	mov    %eax,%ebx
}
  801fa9:	89 d8                	mov    %ebx,%eax
  801fab:	8b 5d f8             	mov    -0x8(%ebp),%ebx
  801fae:	8b 75 fc             	mov    -0x4(%ebp),%esi
  801fb1:	89 ec                	mov    %ebp,%esp
  801fb3:	5d                   	pop    %ebp
  801fb4:	c3                   	ret    
	...

00801fc0 <devsock_stat>:
	return nsipc_send(fd->fd_sock.sockid, buf, n, 0);
}

static int
devsock_stat(struct Fd *fd, struct Stat *stat)
{
  801fc0:	55                   	push   %ebp
  801fc1:	89 e5                	mov    %esp,%ebp
  801fc3:	83 ec 18             	sub    $0x18,%esp
	strcpy(stat->st_name, "<sock>");
  801fc6:	c7 44 24 04 98 33 80 	movl   $0x803398,0x4(%esp)
  801fcd:	00 
  801fce:	8b 45 0c             	mov    0xc(%ebp),%eax
  801fd1:	89 04 24             	mov    %eax,(%esp)
  801fd4:	e8 71 e9 ff ff       	call   80094a <strcpy>
	return 0;
}
  801fd9:	b8 00 00 00 00       	mov    $0x0,%eax
  801fde:	c9                   	leave  
  801fdf:	c3                   	ret    

00801fe0 <devsock_close>:
	return nsipc_shutdown(r, how);
}

static int
devsock_close(struct Fd *fd)
{
  801fe0:	55                   	push   %ebp
  801fe1:	89 e5                	mov    %esp,%ebp
  801fe3:	83 ec 18             	sub    $0x18,%esp
	return nsipc_close(fd->fd_sock.sockid);
  801fe6:	8b 45 08             	mov    0x8(%ebp),%eax
  801fe9:	8b 40 0c             	mov    0xc(%eax),%eax
  801fec:	89 04 24             	mov    %eax,(%esp)
  801fef:	e8 9d 02 00 00       	call   802291 <nsipc_close>
}
  801ff4:	c9                   	leave  
  801ff5:	c3                   	ret    

00801ff6 <devsock_write>:
	return nsipc_recv(fd->fd_sock.sockid, buf, n, 0);
}

static ssize_t
devsock_write(struct Fd *fd, const void *buf, size_t n)
{
  801ff6:	55                   	push   %ebp
  801ff7:	89 e5                	mov    %esp,%ebp
  801ff9:	83 ec 18             	sub    $0x18,%esp
	return nsipc_send(fd->fd_sock.sockid, buf, n, 0);
  801ffc:	c7 44 24 0c 00 00 00 	movl   $0x0,0xc(%esp)
  802003:	00 
  802004:	8b 45 10             	mov    0x10(%ebp),%eax
  802007:	89 44 24 08          	mov    %eax,0x8(%esp)
  80200b:	8b 45 0c             	mov    0xc(%ebp),%eax
  80200e:	89 44 24 04          	mov    %eax,0x4(%esp)
  802012:	8b 45 08             	mov    0x8(%ebp),%eax
  802015:	8b 40 0c             	mov    0xc(%eax),%eax
  802018:	89 04 24             	mov    %eax,(%esp)
  80201b:	e8 ad 02 00 00       	call   8022cd <nsipc_send>
}
  802020:	c9                   	leave  
  802021:	c3                   	ret    

00802022 <devsock_read>:
	return nsipc_listen(r, backlog);
}

static ssize_t
devsock_read(struct Fd *fd, void *buf, size_t n)
{
  802022:	55                   	push   %ebp
  802023:	89 e5                	mov    %esp,%ebp
  802025:	83 ec 18             	sub    $0x18,%esp
	return nsipc_recv(fd->fd_sock.sockid, buf, n, 0);
  802028:	c7 44 24 0c 00 00 00 	movl   $0x0,0xc(%esp)
  80202f:	00 
  802030:	8b 45 10             	mov    0x10(%ebp),%eax
  802033:	89 44 24 08          	mov    %eax,0x8(%esp)
  802037:	8b 45 0c             	mov    0xc(%ebp),%eax
  80203a:	89 44 24 04          	mov    %eax,0x4(%esp)
  80203e:	8b 45 08             	mov    0x8(%ebp),%eax
  802041:	8b 40 0c             	mov    0xc(%eax),%eax
  802044:	89 04 24             	mov    %eax,(%esp)
  802047:	e8 f4 02 00 00       	call   802340 <nsipc_recv>
}
  80204c:	c9                   	leave  
  80204d:	c3                   	ret    

0080204e <alloc_sockfd>:
	return sfd->fd_sock.sockid;
}

static int
alloc_sockfd(int sockid)
{
  80204e:	55                   	push   %ebp
  80204f:	89 e5                	mov    %esp,%ebp
  802051:	56                   	push   %esi
  802052:	53                   	push   %ebx
  802053:	83 ec 20             	sub    $0x20,%esp
  802056:	89 c6                	mov    %eax,%esi
	struct Fd *sfd;
	int r;

	if ((r = fd_alloc(&sfd)) < 0
  802058:	8d 45 f4             	lea    -0xc(%ebp),%eax
  80205b:	89 04 24             	mov    %eax,(%esp)
  80205e:	e8 68 f6 ff ff       	call   8016cb <fd_alloc>
  802063:	89 c3                	mov    %eax,%ebx
  802065:	85 c0                	test   %eax,%eax
  802067:	78 21                	js     80208a <alloc_sockfd+0x3c>
	    || (r = sys_page_alloc(0, sfd, PTE_P|PTE_W|PTE_U)) < 0) {
  802069:	c7 44 24 08 07 00 00 	movl   $0x7,0x8(%esp)
  802070:	00 
  802071:	8b 45 f4             	mov    -0xc(%ebp),%eax
  802074:	89 44 24 04          	mov    %eax,0x4(%esp)
  802078:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  80207f:	e8 22 f0 ff ff       	call   8010a6 <sys_page_alloc>
  802084:	89 c3                	mov    %eax,%ebx
alloc_sockfd(int sockid)
{
	struct Fd *sfd;
	int r;

	if ((r = fd_alloc(&sfd)) < 0
  802086:	85 c0                	test   %eax,%eax
  802088:	79 0a                	jns    802094 <alloc_sockfd+0x46>
	    || (r = sys_page_alloc(0, sfd, PTE_P|PTE_W|PTE_U)) < 0) {
		nsipc_close(sockid);
  80208a:	89 34 24             	mov    %esi,(%esp)
  80208d:	e8 ff 01 00 00       	call   802291 <nsipc_close>
		return r;
  802092:	eb 28                	jmp    8020bc <alloc_sockfd+0x6e>
	}

	sfd->fd_dev_id = devsock.dev_id;
  802094:	8b 15 20 70 80 00    	mov    0x807020,%edx
  80209a:	8b 45 f4             	mov    -0xc(%ebp),%eax
  80209d:	89 10                	mov    %edx,(%eax)
	sfd->fd_omode = O_RDWR;
  80209f:	8b 45 f4             	mov    -0xc(%ebp),%eax
  8020a2:	c7 40 08 02 00 00 00 	movl   $0x2,0x8(%eax)
	sfd->fd_sock.sockid = sockid;
  8020a9:	8b 45 f4             	mov    -0xc(%ebp),%eax
  8020ac:	89 70 0c             	mov    %esi,0xc(%eax)
	return fd2num(sfd);
  8020af:	8b 45 f4             	mov    -0xc(%ebp),%eax
  8020b2:	89 04 24             	mov    %eax,(%esp)
  8020b5:	e8 e6 f5 ff ff       	call   8016a0 <fd2num>
  8020ba:	89 c3                	mov    %eax,%ebx
}
  8020bc:	89 d8                	mov    %ebx,%eax
  8020be:	83 c4 20             	add    $0x20,%esp
  8020c1:	5b                   	pop    %ebx
  8020c2:	5e                   	pop    %esi
  8020c3:	5d                   	pop    %ebp
  8020c4:	c3                   	ret    

008020c5 <socket>:
	return 0;
}

int
socket(int domain, int type, int protocol)
{
  8020c5:	55                   	push   %ebp
  8020c6:	89 e5                	mov    %esp,%ebp
  8020c8:	83 ec 18             	sub    $0x18,%esp
	int r;
	if ((r = nsipc_socket(domain, type, protocol)) < 0)
  8020cb:	8b 45 10             	mov    0x10(%ebp),%eax
  8020ce:	89 44 24 08          	mov    %eax,0x8(%esp)
  8020d2:	8b 45 0c             	mov    0xc(%ebp),%eax
  8020d5:	89 44 24 04          	mov    %eax,0x4(%esp)
  8020d9:	8b 45 08             	mov    0x8(%ebp),%eax
  8020dc:	89 04 24             	mov    %eax,(%esp)
  8020df:	e8 61 01 00 00       	call   802245 <nsipc_socket>
  8020e4:	85 c0                	test   %eax,%eax
  8020e6:	78 05                	js     8020ed <socket+0x28>
		return r;
	return alloc_sockfd(r);
  8020e8:	e8 61 ff ff ff       	call   80204e <alloc_sockfd>
}
  8020ed:	c9                   	leave  
  8020ee:	66 90                	xchg   %ax,%ax
  8020f0:	c3                   	ret    

008020f1 <fd2sockid>:
	.dev_stat =	devsock_stat,
};

static int
fd2sockid(int fd)
{
  8020f1:	55                   	push   %ebp
  8020f2:	89 e5                	mov    %esp,%ebp
  8020f4:	83 ec 28             	sub    $0x28,%esp
	struct Fd *sfd;
	int r;

	if ((r = fd_lookup(fd, &sfd)) < 0)
  8020f7:	8d 55 f4             	lea    -0xc(%ebp),%edx
  8020fa:	89 54 24 04          	mov    %edx,0x4(%esp)
  8020fe:	89 04 24             	mov    %eax,(%esp)
  802101:	e8 37 f6 ff ff       	call   80173d <fd_lookup>
  802106:	85 c0                	test   %eax,%eax
  802108:	78 15                	js     80211f <fd2sockid+0x2e>
		return r;
	if (sfd->fd_dev_id != devsock.dev_id)
  80210a:	8b 55 f4             	mov    -0xc(%ebp),%edx
  80210d:	8b 0a                	mov    (%edx),%ecx
  80210f:	b8 f1 ff ff ff       	mov    $0xfffffff1,%eax
  802114:	3b 0d 20 70 80 00    	cmp    0x807020,%ecx
  80211a:	75 03                	jne    80211f <fd2sockid+0x2e>
		return -E_NOT_SUPP;
	return sfd->fd_sock.sockid;
  80211c:	8b 42 0c             	mov    0xc(%edx),%eax
}
  80211f:	c9                   	leave  
  802120:	c3                   	ret    

00802121 <listen>:
	return nsipc_connect(r, name, namelen);
}

int
listen(int s, int backlog)
{
  802121:	55                   	push   %ebp
  802122:	89 e5                	mov    %esp,%ebp
  802124:	83 ec 18             	sub    $0x18,%esp
	int r;
	if ((r = fd2sockid(s)) < 0)
  802127:	8b 45 08             	mov    0x8(%ebp),%eax
  80212a:	e8 c2 ff ff ff       	call   8020f1 <fd2sockid>
  80212f:	85 c0                	test   %eax,%eax
  802131:	78 0f                	js     802142 <listen+0x21>
		return r;
	return nsipc_listen(r, backlog);
  802133:	8b 55 0c             	mov    0xc(%ebp),%edx
  802136:	89 54 24 04          	mov    %edx,0x4(%esp)
  80213a:	89 04 24             	mov    %eax,(%esp)
  80213d:	e8 2d 01 00 00       	call   80226f <nsipc_listen>
}
  802142:	c9                   	leave  
  802143:	c3                   	ret    

00802144 <connect>:
	return nsipc_close(fd->fd_sock.sockid);
}

int
connect(int s, const struct sockaddr *name, socklen_t namelen)
{
  802144:	55                   	push   %ebp
  802145:	89 e5                	mov    %esp,%ebp
  802147:	83 ec 18             	sub    $0x18,%esp
	int r;
	if ((r = fd2sockid(s)) < 0)
  80214a:	8b 45 08             	mov    0x8(%ebp),%eax
  80214d:	e8 9f ff ff ff       	call   8020f1 <fd2sockid>
  802152:	85 c0                	test   %eax,%eax
  802154:	78 16                	js     80216c <connect+0x28>
		return r;
	return nsipc_connect(r, name, namelen);
  802156:	8b 55 10             	mov    0x10(%ebp),%edx
  802159:	89 54 24 08          	mov    %edx,0x8(%esp)
  80215d:	8b 55 0c             	mov    0xc(%ebp),%edx
  802160:	89 54 24 04          	mov    %edx,0x4(%esp)
  802164:	89 04 24             	mov    %eax,(%esp)
  802167:	e8 54 02 00 00       	call   8023c0 <nsipc_connect>
}
  80216c:	c9                   	leave  
  80216d:	c3                   	ret    

0080216e <shutdown>:
	return nsipc_bind(r, name, namelen);
}

int
shutdown(int s, int how)
{
  80216e:	55                   	push   %ebp
  80216f:	89 e5                	mov    %esp,%ebp
  802171:	83 ec 18             	sub    $0x18,%esp
	int r;
	if ((r = fd2sockid(s)) < 0)
  802174:	8b 45 08             	mov    0x8(%ebp),%eax
  802177:	e8 75 ff ff ff       	call   8020f1 <fd2sockid>
  80217c:	85 c0                	test   %eax,%eax
  80217e:	78 0f                	js     80218f <shutdown+0x21>
		return r;
	return nsipc_shutdown(r, how);
  802180:	8b 55 0c             	mov    0xc(%ebp),%edx
  802183:	89 54 24 04          	mov    %edx,0x4(%esp)
  802187:	89 04 24             	mov    %eax,(%esp)
  80218a:	e8 1c 01 00 00       	call   8022ab <nsipc_shutdown>
}
  80218f:	c9                   	leave  
  802190:	c3                   	ret    

00802191 <bind>:
	return alloc_sockfd(r);
}

int
bind(int s, struct sockaddr *name, socklen_t namelen)
{
  802191:	55                   	push   %ebp
  802192:	89 e5                	mov    %esp,%ebp
  802194:	83 ec 18             	sub    $0x18,%esp
	int r;
	if ((r = fd2sockid(s)) < 0)
  802197:	8b 45 08             	mov    0x8(%ebp),%eax
  80219a:	e8 52 ff ff ff       	call   8020f1 <fd2sockid>
  80219f:	85 c0                	test   %eax,%eax
  8021a1:	78 16                	js     8021b9 <bind+0x28>
		return r;
	return nsipc_bind(r, name, namelen);
  8021a3:	8b 55 10             	mov    0x10(%ebp),%edx
  8021a6:	89 54 24 08          	mov    %edx,0x8(%esp)
  8021aa:	8b 55 0c             	mov    0xc(%ebp),%edx
  8021ad:	89 54 24 04          	mov    %edx,0x4(%esp)
  8021b1:	89 04 24             	mov    %eax,(%esp)
  8021b4:	e8 46 02 00 00       	call   8023ff <nsipc_bind>
}
  8021b9:	c9                   	leave  
  8021ba:	c3                   	ret    

008021bb <accept>:
	return fd2num(sfd);
}

int
accept(int s, struct sockaddr *addr, socklen_t *addrlen)
{
  8021bb:	55                   	push   %ebp
  8021bc:	89 e5                	mov    %esp,%ebp
  8021be:	83 ec 18             	sub    $0x18,%esp
	int r;
	if ((r = fd2sockid(s)) < 0)
  8021c1:	8b 45 08             	mov    0x8(%ebp),%eax
  8021c4:	e8 28 ff ff ff       	call   8020f1 <fd2sockid>
  8021c9:	85 c0                	test   %eax,%eax
  8021cb:	78 1f                	js     8021ec <accept+0x31>
		return r;
	if ((r = nsipc_accept(r, addr, addrlen)) < 0)
  8021cd:	8b 55 10             	mov    0x10(%ebp),%edx
  8021d0:	89 54 24 08          	mov    %edx,0x8(%esp)
  8021d4:	8b 55 0c             	mov    0xc(%ebp),%edx
  8021d7:	89 54 24 04          	mov    %edx,0x4(%esp)
  8021db:	89 04 24             	mov    %eax,(%esp)
  8021de:	e8 5b 02 00 00       	call   80243e <nsipc_accept>
  8021e3:	85 c0                	test   %eax,%eax
  8021e5:	78 05                	js     8021ec <accept+0x31>
		return r;
	return alloc_sockfd(r);
  8021e7:	e8 62 fe ff ff       	call   80204e <alloc_sockfd>
}
  8021ec:	c9                   	leave  
  8021ed:	8d 76 00             	lea    0x0(%esi),%esi
  8021f0:	c3                   	ret    
	...

00802200 <nsipc>:
// may be written back to nsipcbuf.
// type: request code, passed as the simple integer IPC value.
// Returns 0 if successful, < 0 on failure.
static int
nsipc(unsigned type)
{
  802200:	55                   	push   %ebp
  802201:	89 e5                	mov    %esp,%ebp
  802203:	83 ec 28             	sub    $0x28,%esp
    int r=0;
    envid_t from;
	if (debug)
		cprintf("[%08x] nsipc %d\n", env->env_id, type);

	ipc_send(envs[2].env_id, type, &nsipcbuf, PTE_P|PTE_W|PTE_U);
  802206:	8b 15 44 01 c0 ee    	mov    0xeec00144,%edx
  80220c:	c7 44 24 0c 07 00 00 	movl   $0x7,0xc(%esp)
  802213:	00 
  802214:	c7 44 24 08 00 60 80 	movl   $0x806000,0x8(%esp)
  80221b:	00 
  80221c:	89 44 24 04          	mov    %eax,0x4(%esp)
  802220:	89 14 24             	mov    %edx,(%esp)
  802223:	e8 a8 f3 ff ff       	call   8015d0 <ipc_send>
	r=ipc_recv(&from, NULL, NULL);
  802228:	c7 44 24 08 00 00 00 	movl   $0x0,0x8(%esp)
  80222f:	00 
  802230:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
  802237:	00 
  802238:	8d 45 f4             	lea    -0xc(%ebp),%eax
  80223b:	89 04 24             	mov    %eax,(%esp)
  80223e:	e8 ff f3 ff ff       	call   801642 <ipc_recv>
    return r;
}
  802243:	c9                   	leave  
  802244:	c3                   	ret    

00802245 <nsipc_socket>:
	return nsipc(NSREQ_SEND);
}

int
nsipc_socket(int domain, int type, int protocol)
{
  802245:	55                   	push   %ebp
  802246:	89 e5                	mov    %esp,%ebp
  802248:	83 ec 08             	sub    $0x8,%esp
	nsipcbuf.socket.req_domain = domain;
  80224b:	8b 45 08             	mov    0x8(%ebp),%eax
  80224e:	a3 00 60 80 00       	mov    %eax,0x806000
	nsipcbuf.socket.req_type = type;
  802253:	8b 45 0c             	mov    0xc(%ebp),%eax
  802256:	a3 04 60 80 00       	mov    %eax,0x806004
	nsipcbuf.socket.req_protocol = protocol;
  80225b:	8b 45 10             	mov    0x10(%ebp),%eax
  80225e:	a3 08 60 80 00       	mov    %eax,0x806008
	return nsipc(NSREQ_SOCKET);
  802263:	b8 09 00 00 00       	mov    $0x9,%eax
  802268:	e8 93 ff ff ff       	call   802200 <nsipc>
}
  80226d:	c9                   	leave  
  80226e:	c3                   	ret    

0080226f <nsipc_listen>:
	return nsipc(NSREQ_CONNECT);
}

int
nsipc_listen(int s, int backlog)
{
  80226f:	55                   	push   %ebp
  802270:	89 e5                	mov    %esp,%ebp
  802272:	83 ec 08             	sub    $0x8,%esp
	nsipcbuf.listen.req_s = s;
  802275:	8b 45 08             	mov    0x8(%ebp),%eax
  802278:	a3 00 60 80 00       	mov    %eax,0x806000
	nsipcbuf.listen.req_backlog = backlog;
  80227d:	8b 45 0c             	mov    0xc(%ebp),%eax
  802280:	a3 04 60 80 00       	mov    %eax,0x806004
	return nsipc(NSREQ_LISTEN);
  802285:	b8 06 00 00 00       	mov    $0x6,%eax
  80228a:	e8 71 ff ff ff       	call   802200 <nsipc>
}
  80228f:	c9                   	leave  
  802290:	c3                   	ret    

00802291 <nsipc_close>:
	return nsipc(NSREQ_SHUTDOWN);
}

int
nsipc_close(int s)
{
  802291:	55                   	push   %ebp
  802292:	89 e5                	mov    %esp,%ebp
  802294:	83 ec 08             	sub    $0x8,%esp
	nsipcbuf.close.req_s = s;
  802297:	8b 45 08             	mov    0x8(%ebp),%eax
  80229a:	a3 00 60 80 00       	mov    %eax,0x806000
	return nsipc(NSREQ_CLOSE);
  80229f:	b8 04 00 00 00       	mov    $0x4,%eax
  8022a4:	e8 57 ff ff ff       	call   802200 <nsipc>
}
  8022a9:	c9                   	leave  
  8022aa:	c3                   	ret    

008022ab <nsipc_shutdown>:
	return nsipc(NSREQ_BIND);
}

int
nsipc_shutdown(int s, int how)
{
  8022ab:	55                   	push   %ebp
  8022ac:	89 e5                	mov    %esp,%ebp
  8022ae:	83 ec 08             	sub    $0x8,%esp
	nsipcbuf.shutdown.req_s = s;
  8022b1:	8b 45 08             	mov    0x8(%ebp),%eax
  8022b4:	a3 00 60 80 00       	mov    %eax,0x806000
	nsipcbuf.shutdown.req_how = how;
  8022b9:	8b 45 0c             	mov    0xc(%ebp),%eax
  8022bc:	a3 04 60 80 00       	mov    %eax,0x806004
	return nsipc(NSREQ_SHUTDOWN);
  8022c1:	b8 03 00 00 00       	mov    $0x3,%eax
  8022c6:	e8 35 ff ff ff       	call   802200 <nsipc>
}
  8022cb:	c9                   	leave  
  8022cc:	c3                   	ret    

008022cd <nsipc_send>:
	return r;
}

int
nsipc_send(int s, const void *buf, int size, unsigned int flags)
{
  8022cd:	55                   	push   %ebp
  8022ce:	89 e5                	mov    %esp,%ebp
  8022d0:	53                   	push   %ebx
  8022d1:	83 ec 14             	sub    $0x14,%esp
  8022d4:	8b 5d 10             	mov    0x10(%ebp),%ebx
	nsipcbuf.send.req_s = s;
  8022d7:	8b 45 08             	mov    0x8(%ebp),%eax
  8022da:	a3 00 60 80 00       	mov    %eax,0x806000
	assert(size < 1600);
  8022df:	81 fb 3f 06 00 00    	cmp    $0x63f,%ebx
  8022e5:	7e 24                	jle    80230b <nsipc_send+0x3e>
  8022e7:	c7 44 24 0c a4 33 80 	movl   $0x8033a4,0xc(%esp)
  8022ee:	00 
  8022ef:	c7 44 24 08 b0 33 80 	movl   $0x8033b0,0x8(%esp)
  8022f6:	00 
  8022f7:	c7 44 24 04 69 00 00 	movl   $0x69,0x4(%esp)
  8022fe:	00 
  8022ff:	c7 04 24 c5 33 80 00 	movl   $0x8033c5,(%esp)
  802306:	e8 a5 de ff ff       	call   8001b0 <_panic>
	memmove(&nsipcbuf.send.req_buf, buf, size);
  80230b:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  80230f:	8b 45 0c             	mov    0xc(%ebp),%eax
  802312:	89 44 24 04          	mov    %eax,0x4(%esp)
  802316:	c7 04 24 0c 60 80 00 	movl   $0x80600c,(%esp)
  80231d:	e8 e3 e7 ff ff       	call   800b05 <memmove>
	nsipcbuf.send.req_size = size;
  802322:	89 1d 04 60 80 00    	mov    %ebx,0x806004
	nsipcbuf.send.req_flags = flags;
  802328:	8b 45 14             	mov    0x14(%ebp),%eax
  80232b:	a3 08 60 80 00       	mov    %eax,0x806008
	return nsipc(NSREQ_SEND);
  802330:	b8 08 00 00 00       	mov    $0x8,%eax
  802335:	e8 c6 fe ff ff       	call   802200 <nsipc>
}
  80233a:	83 c4 14             	add    $0x14,%esp
  80233d:	5b                   	pop    %ebx
  80233e:	5d                   	pop    %ebp
  80233f:	c3                   	ret    

00802340 <nsipc_recv>:
	return nsipc(NSREQ_LISTEN);
}

int
nsipc_recv(int s, void *mem, int len, unsigned int flags)
{
  802340:	55                   	push   %ebp
  802341:	89 e5                	mov    %esp,%ebp
  802343:	56                   	push   %esi
  802344:	53                   	push   %ebx
  802345:	83 ec 10             	sub    $0x10,%esp
  802348:	8b 75 10             	mov    0x10(%ebp),%esi
	int r;

	nsipcbuf.recv.req_s = s;
  80234b:	8b 45 08             	mov    0x8(%ebp),%eax
  80234e:	a3 00 60 80 00       	mov    %eax,0x806000
	nsipcbuf.recv.req_len = len;
  802353:	89 35 04 60 80 00    	mov    %esi,0x806004
	nsipcbuf.recv.req_flags = flags;
  802359:	8b 45 14             	mov    0x14(%ebp),%eax
  80235c:	a3 08 60 80 00       	mov    %eax,0x806008

	if ((r = nsipc(NSREQ_RECV)) >= 0) {
  802361:	b8 07 00 00 00       	mov    $0x7,%eax
  802366:	e8 95 fe ff ff       	call   802200 <nsipc>
  80236b:	89 c3                	mov    %eax,%ebx
  80236d:	85 c0                	test   %eax,%eax
  80236f:	78 46                	js     8023b7 <nsipc_recv+0x77>
		assert(r < 1600 && r <= len);
  802371:	3d 3f 06 00 00       	cmp    $0x63f,%eax
  802376:	7f 04                	jg     80237c <nsipc_recv+0x3c>
  802378:	39 c6                	cmp    %eax,%esi
  80237a:	7d 24                	jge    8023a0 <nsipc_recv+0x60>
  80237c:	c7 44 24 0c d1 33 80 	movl   $0x8033d1,0xc(%esp)
  802383:	00 
  802384:	c7 44 24 08 b0 33 80 	movl   $0x8033b0,0x8(%esp)
  80238b:	00 
  80238c:	c7 44 24 04 5e 00 00 	movl   $0x5e,0x4(%esp)
  802393:	00 
  802394:	c7 04 24 c5 33 80 00 	movl   $0x8033c5,(%esp)
  80239b:	e8 10 de ff ff       	call   8001b0 <_panic>
		memmove(mem, nsipcbuf.recvRet.ret_buf, r);
  8023a0:	89 44 24 08          	mov    %eax,0x8(%esp)
  8023a4:	c7 44 24 04 00 60 80 	movl   $0x806000,0x4(%esp)
  8023ab:	00 
  8023ac:	8b 45 0c             	mov    0xc(%ebp),%eax
  8023af:	89 04 24             	mov    %eax,(%esp)
  8023b2:	e8 4e e7 ff ff       	call   800b05 <memmove>
	}

	return r;
}
  8023b7:	89 d8                	mov    %ebx,%eax
  8023b9:	83 c4 10             	add    $0x10,%esp
  8023bc:	5b                   	pop    %ebx
  8023bd:	5e                   	pop    %esi
  8023be:	5d                   	pop    %ebp
  8023bf:	c3                   	ret    

008023c0 <nsipc_connect>:
	return nsipc(NSREQ_CLOSE);
}

int
nsipc_connect(int s, const struct sockaddr *name, socklen_t namelen)
{
  8023c0:	55                   	push   %ebp
  8023c1:	89 e5                	mov    %esp,%ebp
  8023c3:	53                   	push   %ebx
  8023c4:	83 ec 14             	sub    $0x14,%esp
  8023c7:	8b 5d 10             	mov    0x10(%ebp),%ebx
	nsipcbuf.connect.req_s = s;
  8023ca:	8b 45 08             	mov    0x8(%ebp),%eax
  8023cd:	a3 00 60 80 00       	mov    %eax,0x806000
	memmove(&nsipcbuf.connect.req_name, name, namelen);
  8023d2:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  8023d6:	8b 45 0c             	mov    0xc(%ebp),%eax
  8023d9:	89 44 24 04          	mov    %eax,0x4(%esp)
  8023dd:	c7 04 24 04 60 80 00 	movl   $0x806004,(%esp)
  8023e4:	e8 1c e7 ff ff       	call   800b05 <memmove>
	nsipcbuf.connect.req_namelen = namelen;
  8023e9:	89 1d 14 60 80 00    	mov    %ebx,0x806014
	return nsipc(NSREQ_CONNECT);
  8023ef:	b8 05 00 00 00       	mov    $0x5,%eax
  8023f4:	e8 07 fe ff ff       	call   802200 <nsipc>
}
  8023f9:	83 c4 14             	add    $0x14,%esp
  8023fc:	5b                   	pop    %ebx
  8023fd:	5d                   	pop    %ebp
  8023fe:	c3                   	ret    

008023ff <nsipc_bind>:
	return r;
}

int
nsipc_bind(int s, struct sockaddr *name, socklen_t namelen)
{
  8023ff:	55                   	push   %ebp
  802400:	89 e5                	mov    %esp,%ebp
  802402:	53                   	push   %ebx
  802403:	83 ec 14             	sub    $0x14,%esp
  802406:	8b 5d 10             	mov    0x10(%ebp),%ebx
	nsipcbuf.bind.req_s = s;
  802409:	8b 45 08             	mov    0x8(%ebp),%eax
  80240c:	a3 00 60 80 00       	mov    %eax,0x806000
	memmove(&nsipcbuf.bind.req_name, name, namelen);
  802411:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  802415:	8b 45 0c             	mov    0xc(%ebp),%eax
  802418:	89 44 24 04          	mov    %eax,0x4(%esp)
  80241c:	c7 04 24 04 60 80 00 	movl   $0x806004,(%esp)
  802423:	e8 dd e6 ff ff       	call   800b05 <memmove>
	nsipcbuf.bind.req_namelen = namelen;
  802428:	89 1d 14 60 80 00    	mov    %ebx,0x806014
	return nsipc(NSREQ_BIND);
  80242e:	b8 02 00 00 00       	mov    $0x2,%eax
  802433:	e8 c8 fd ff ff       	call   802200 <nsipc>
}
  802438:	83 c4 14             	add    $0x14,%esp
  80243b:	5b                   	pop    %ebx
  80243c:	5d                   	pop    %ebp
  80243d:	c3                   	ret    

0080243e <nsipc_accept>:
    return r;
}

int
nsipc_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
{
  80243e:	55                   	push   %ebp
  80243f:	89 e5                	mov    %esp,%ebp
  802441:	83 ec 18             	sub    $0x18,%esp
  802444:	89 5d f8             	mov    %ebx,-0x8(%ebp)
  802447:	89 75 fc             	mov    %esi,-0x4(%ebp)
	int r;
	
	nsipcbuf.accept.req_s = s;
  80244a:	8b 45 08             	mov    0x8(%ebp),%eax
  80244d:	a3 00 60 80 00       	mov    %eax,0x806000
	if ((r = nsipc(NSREQ_ACCEPT)) >= 0) {
  802452:	b8 01 00 00 00       	mov    $0x1,%eax
  802457:	e8 a4 fd ff ff       	call   802200 <nsipc>
  80245c:	89 c3                	mov    %eax,%ebx
  80245e:	85 c0                	test   %eax,%eax
  802460:	78 25                	js     802487 <nsipc_accept+0x49>
		struct Nsret_accept *ret = &nsipcbuf.acceptRet;
		memmove(addr, &ret->ret_addr, ret->ret_addrlen);
  802462:	be 10 60 80 00       	mov    $0x806010,%esi
  802467:	8b 06                	mov    (%esi),%eax
  802469:	89 44 24 08          	mov    %eax,0x8(%esp)
  80246d:	c7 44 24 04 00 60 80 	movl   $0x806000,0x4(%esp)
  802474:	00 
  802475:	8b 45 0c             	mov    0xc(%ebp),%eax
  802478:	89 04 24             	mov    %eax,(%esp)
  80247b:	e8 85 e6 ff ff       	call   800b05 <memmove>
		*addrlen = ret->ret_addrlen;
  802480:	8b 16                	mov    (%esi),%edx
  802482:	8b 45 10             	mov    0x10(%ebp),%eax
  802485:	89 10                	mov    %edx,(%eax)
	}
	return r;
}
  802487:	89 d8                	mov    %ebx,%eax
  802489:	8b 5d f8             	mov    -0x8(%ebp),%ebx
  80248c:	8b 75 fc             	mov    -0x4(%ebp),%esi
  80248f:	89 ec                	mov    %ebp,%esp
  802491:	5d                   	pop    %ebp
  802492:	c3                   	ret    
	...

008024a0 <devpipe_stat>:
	return i;
}

static int
devpipe_stat(struct Fd *fd, struct Stat *stat)
{
  8024a0:	55                   	push   %ebp
  8024a1:	89 e5                	mov    %esp,%ebp
  8024a3:	83 ec 18             	sub    $0x18,%esp
  8024a6:	89 5d f8             	mov    %ebx,-0x8(%ebp)
  8024a9:	89 75 fc             	mov    %esi,-0x4(%ebp)
  8024ac:	8b 75 0c             	mov    0xc(%ebp),%esi
	struct Pipe *p = (struct Pipe*) fd2data(fd);
  8024af:	8b 45 08             	mov    0x8(%ebp),%eax
  8024b2:	89 04 24             	mov    %eax,(%esp)
  8024b5:	e8 f6 f1 ff ff       	call   8016b0 <fd2data>
  8024ba:	89 c3                	mov    %eax,%ebx
	strcpy(stat->st_name, "<pipe>");
  8024bc:	c7 44 24 04 e6 33 80 	movl   $0x8033e6,0x4(%esp)
  8024c3:	00 
  8024c4:	89 34 24             	mov    %esi,(%esp)
  8024c7:	e8 7e e4 ff ff       	call   80094a <strcpy>
	stat->st_size = p->p_wpos - p->p_rpos;
  8024cc:	8b 43 04             	mov    0x4(%ebx),%eax
  8024cf:	2b 03                	sub    (%ebx),%eax
  8024d1:	89 86 80 00 00 00    	mov    %eax,0x80(%esi)
	stat->st_isdir = 0;
  8024d7:	c7 86 84 00 00 00 00 	movl   $0x0,0x84(%esi)
  8024de:	00 00 00 
	stat->st_dev = &devpipe;
  8024e1:	c7 86 88 00 00 00 3c 	movl   $0x80703c,0x88(%esi)
  8024e8:	70 80 00 
	return 0;
}
  8024eb:	b8 00 00 00 00       	mov    $0x0,%eax
  8024f0:	8b 5d f8             	mov    -0x8(%ebp),%ebx
  8024f3:	8b 75 fc             	mov    -0x4(%ebp),%esi
  8024f6:	89 ec                	mov    %ebp,%esp
  8024f8:	5d                   	pop    %ebp
  8024f9:	c3                   	ret    

008024fa <devpipe_close>:

static int
devpipe_close(struct Fd *fd)
{
  8024fa:	55                   	push   %ebp
  8024fb:	89 e5                	mov    %esp,%ebp
  8024fd:	53                   	push   %ebx
  8024fe:	83 ec 14             	sub    $0x14,%esp
  802501:	8b 5d 08             	mov    0x8(%ebp),%ebx
	(void) sys_page_unmap(0, fd);
  802504:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  802508:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  80250f:	e8 d6 ea ff ff       	call   800fea <sys_page_unmap>
	return sys_page_unmap(0, fd2data(fd));
  802514:	89 1c 24             	mov    %ebx,(%esp)
  802517:	e8 94 f1 ff ff       	call   8016b0 <fd2data>
  80251c:	89 44 24 04          	mov    %eax,0x4(%esp)
  802520:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  802527:	e8 be ea ff ff       	call   800fea <sys_page_unmap>
}
  80252c:	83 c4 14             	add    $0x14,%esp
  80252f:	5b                   	pop    %ebx
  802530:	5d                   	pop    %ebp
  802531:	c3                   	ret    

00802532 <_pipeisclosed>:
	return r;
}

static int
_pipeisclosed(struct Fd *fd, struct Pipe *p)
{
  802532:	55                   	push   %ebp
  802533:	89 e5                	mov    %esp,%ebp
  802535:	57                   	push   %edi
  802536:	56                   	push   %esi
  802537:	53                   	push   %ebx
  802538:	83 ec 2c             	sub    $0x2c,%esp
  80253b:	89 c7                	mov    %eax,%edi
  80253d:	89 55 e4             	mov    %edx,-0x1c(%ebp)
	int n, nn, ret;

	while (1) {
		n = env->env_runs;
  802540:	a1 74 70 80 00       	mov    0x807074,%eax
  802545:	8b 58 58             	mov    0x58(%eax),%ebx
		ret = pageref(fd) == pageref(p);
  802548:	89 3c 24             	mov    %edi,(%esp)
  80254b:	e8 7c 05 00 00       	call   802acc <pageref>
  802550:	89 c6                	mov    %eax,%esi
  802552:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  802555:	89 04 24             	mov    %eax,(%esp)
  802558:	e8 6f 05 00 00       	call   802acc <pageref>
  80255d:	39 c6                	cmp    %eax,%esi
  80255f:	0f 94 c0             	sete   %al
  802562:	0f b6 c0             	movzbl %al,%eax
		nn = env->env_runs;
  802565:	8b 15 74 70 80 00    	mov    0x807074,%edx
  80256b:	8b 4a 58             	mov    0x58(%edx),%ecx
		if (n == nn)
  80256e:	39 cb                	cmp    %ecx,%ebx
  802570:	75 08                	jne    80257a <_pipeisclosed+0x48>
			return ret;
		if (n != nn && ret == 1)
			cprintf("pipe race avoided\n", n, env->env_runs, ret);
	}
}
  802572:	83 c4 2c             	add    $0x2c,%esp
  802575:	5b                   	pop    %ebx
  802576:	5e                   	pop    %esi
  802577:	5f                   	pop    %edi
  802578:	5d                   	pop    %ebp
  802579:	c3                   	ret    
		n = env->env_runs;
		ret = pageref(fd) == pageref(p);
		nn = env->env_runs;
		if (n == nn)
			return ret;
		if (n != nn && ret == 1)
  80257a:	83 f8 01             	cmp    $0x1,%eax
  80257d:	75 c1                	jne    802540 <_pipeisclosed+0xe>
			cprintf("pipe race avoided\n", n, env->env_runs, ret);
  80257f:	8b 52 58             	mov    0x58(%edx),%edx
  802582:	89 44 24 0c          	mov    %eax,0xc(%esp)
  802586:	89 54 24 08          	mov    %edx,0x8(%esp)
  80258a:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  80258e:	c7 04 24 ed 33 80 00 	movl   $0x8033ed,(%esp)
  802595:	e8 db dc ff ff       	call   800275 <cprintf>
  80259a:	eb a4                	jmp    802540 <_pipeisclosed+0xe>

0080259c <devpipe_write>:
	return i;
}

static ssize_t
devpipe_write(struct Fd *fd, const void *vbuf, size_t n)
{
  80259c:	55                   	push   %ebp
  80259d:	89 e5                	mov    %esp,%ebp
  80259f:	57                   	push   %edi
  8025a0:	56                   	push   %esi
  8025a1:	53                   	push   %ebx
  8025a2:	83 ec 1c             	sub    $0x1c,%esp
  8025a5:	8b 75 08             	mov    0x8(%ebp),%esi
	const uint8_t *buf;
	size_t i;
	struct Pipe *p;

	p = (struct Pipe*) fd2data(fd);
  8025a8:	89 34 24             	mov    %esi,(%esp)
  8025ab:	e8 00 f1 ff ff       	call   8016b0 <fd2data>
  8025b0:	89 c3                	mov    %eax,%ebx
	if (debug)
		cprintf("[%08x] devpipe_write %08x %d rpos %d wpos %d\n",
			env->env_id, vpt[VPN(p)], n, p->p_rpos, p->p_wpos);

	buf = vbuf;
	for (i = 0; i < n; i++) {
  8025b2:	bf 00 00 00 00       	mov    $0x0,%edi
  8025b7:	83 7d 10 00          	cmpl   $0x0,0x10(%ebp)
  8025bb:	75 54                	jne    802611 <devpipe_write+0x75>
  8025bd:	eb 60                	jmp    80261f <devpipe_write+0x83>
		while (p->p_wpos >= p->p_rpos + sizeof(p->p_buf)) {
			// pipe is full
			// if all the readers are gone
			// (it's only writers like us now),
			// note eof
			if (_pipeisclosed(fd, p))
  8025bf:	89 da                	mov    %ebx,%edx
  8025c1:	89 f0                	mov    %esi,%eax
  8025c3:	e8 6a ff ff ff       	call   802532 <_pipeisclosed>
  8025c8:	85 c0                	test   %eax,%eax
  8025ca:	74 07                	je     8025d3 <devpipe_write+0x37>
  8025cc:	b8 00 00 00 00       	mov    $0x0,%eax
  8025d1:	eb 53                	jmp    802626 <devpipe_write+0x8a>
				return 0;
			// yield and see what happens
			if (debug)
				cprintf("devpipe_write yield\n");
			sys_yield();
  8025d3:	90                   	nop
  8025d4:	8d 74 26 00          	lea    0x0(%esi,%eiz,1),%esi
  8025d8:	e8 28 eb ff ff       	call   801105 <sys_yield>
		cprintf("[%08x] devpipe_write %08x %d rpos %d wpos %d\n",
			env->env_id, vpt[VPN(p)], n, p->p_rpos, p->p_wpos);

	buf = vbuf;
	for (i = 0; i < n; i++) {
		while (p->p_wpos >= p->p_rpos + sizeof(p->p_buf)) {
  8025dd:	8b 43 04             	mov    0x4(%ebx),%eax
  8025e0:	8b 13                	mov    (%ebx),%edx
  8025e2:	83 c2 20             	add    $0x20,%edx
  8025e5:	39 d0                	cmp    %edx,%eax
  8025e7:	73 d6                	jae    8025bf <devpipe_write+0x23>
				cprintf("devpipe_write yield\n");
			sys_yield();
		}
		// there's room for a byte.  store it.
		// wait to increment wpos until the byte is stored!
		p->p_buf[p->p_wpos % PIPEBUFSIZ] = buf[i];
  8025e9:	89 c2                	mov    %eax,%edx
  8025eb:	c1 fa 1f             	sar    $0x1f,%edx
  8025ee:	c1 ea 1b             	shr    $0x1b,%edx
  8025f1:	01 d0                	add    %edx,%eax
  8025f3:	83 e0 1f             	and    $0x1f,%eax
  8025f6:	29 d0                	sub    %edx,%eax
  8025f8:	89 c2                	mov    %eax,%edx
  8025fa:	8b 4d 0c             	mov    0xc(%ebp),%ecx
  8025fd:	0f b6 04 39          	movzbl (%ecx,%edi,1),%eax
  802601:	88 44 13 08          	mov    %al,0x8(%ebx,%edx,1)
		p->p_wpos++;
  802605:	83 43 04 01          	addl   $0x1,0x4(%ebx)
	if (debug)
		cprintf("[%08x] devpipe_write %08x %d rpos %d wpos %d\n",
			env->env_id, vpt[VPN(p)], n, p->p_rpos, p->p_wpos);

	buf = vbuf;
	for (i = 0; i < n; i++) {
  802609:	83 c7 01             	add    $0x1,%edi
  80260c:	39 7d 10             	cmp    %edi,0x10(%ebp)
  80260f:	76 13                	jbe    802624 <devpipe_write+0x88>
		while (p->p_wpos >= p->p_rpos + sizeof(p->p_buf)) {
  802611:	8b 43 04             	mov    0x4(%ebx),%eax
  802614:	8b 13                	mov    (%ebx),%edx
  802616:	83 c2 20             	add    $0x20,%edx
  802619:	39 d0                	cmp    %edx,%eax
  80261b:	73 a2                	jae    8025bf <devpipe_write+0x23>
  80261d:	eb ca                	jmp    8025e9 <devpipe_write+0x4d>
  80261f:	bf 00 00 00 00       	mov    $0x0,%edi
		// wait to increment wpos until the byte is stored!
		p->p_buf[p->p_wpos % PIPEBUFSIZ] = buf[i];
		p->p_wpos++;
	}
	
	return i;
  802624:	89 f8                	mov    %edi,%eax
}
  802626:	83 c4 1c             	add    $0x1c,%esp
  802629:	5b                   	pop    %ebx
  80262a:	5e                   	pop    %esi
  80262b:	5f                   	pop    %edi
  80262c:	5d                   	pop    %ebp
  80262d:	c3                   	ret    

0080262e <devpipe_read>:
	return _pipeisclosed(fd, p);
}

static ssize_t
devpipe_read(struct Fd *fd, void *vbuf, size_t n)
{
  80262e:	55                   	push   %ebp
  80262f:	89 e5                	mov    %esp,%ebp
  802631:	83 ec 28             	sub    $0x28,%esp
  802634:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  802637:	89 75 f8             	mov    %esi,-0x8(%ebp)
  80263a:	89 7d fc             	mov    %edi,-0x4(%ebp)
  80263d:	8b 7d 08             	mov    0x8(%ebp),%edi
	uint8_t *buf;
	size_t i;
	struct Pipe *p;

	p = (struct Pipe*)fd2data(fd);
  802640:	89 3c 24             	mov    %edi,(%esp)
  802643:	e8 68 f0 ff ff       	call   8016b0 <fd2data>
  802648:	89 c3                	mov    %eax,%ebx
	if (debug)
		cprintf("[%08x] devpipe_read %08x %d rpos %d wpos %d\n",
			env->env_id, vpt[VPN(p)], n, p->p_rpos, p->p_wpos);

	buf = vbuf;
	for (i = 0; i < n; i++) {
  80264a:	be 00 00 00 00       	mov    $0x0,%esi
  80264f:	83 7d 10 00          	cmpl   $0x0,0x10(%ebp)
  802653:	75 4c                	jne    8026a1 <devpipe_read+0x73>
  802655:	eb 5b                	jmp    8026b2 <devpipe_read+0x84>
		while (p->p_rpos == p->p_wpos) {
			// pipe is empty
			// if we got any data, return it
			if (i > 0)
				return i;
  802657:	89 f0                	mov    %esi,%eax
  802659:	eb 5e                	jmp    8026b9 <devpipe_read+0x8b>
			// if all the writers are gone, note eof
			if (_pipeisclosed(fd, p))
  80265b:	89 da                	mov    %ebx,%edx
  80265d:	89 f8                	mov    %edi,%eax
  80265f:	90                   	nop
  802660:	e8 cd fe ff ff       	call   802532 <_pipeisclosed>
  802665:	85 c0                	test   %eax,%eax
  802667:	74 07                	je     802670 <devpipe_read+0x42>
  802669:	b8 00 00 00 00       	mov    $0x0,%eax
  80266e:	eb 49                	jmp    8026b9 <devpipe_read+0x8b>
				return 0;
			// yield and see what happens
			if (debug)
				cprintf("devpipe_read yield\n");
			sys_yield();
  802670:	e8 90 ea ff ff       	call   801105 <sys_yield>
		cprintf("[%08x] devpipe_read %08x %d rpos %d wpos %d\n",
			env->env_id, vpt[VPN(p)], n, p->p_rpos, p->p_wpos);

	buf = vbuf;
	for (i = 0; i < n; i++) {
		while (p->p_rpos == p->p_wpos) {
  802675:	8b 03                	mov    (%ebx),%eax
  802677:	3b 43 04             	cmp    0x4(%ebx),%eax
  80267a:	74 df                	je     80265b <devpipe_read+0x2d>
				cprintf("devpipe_read yield\n");
			sys_yield();
		}
		// there's a byte.  take it.
		// wait to increment rpos until the byte is taken!
		buf[i] = p->p_buf[p->p_rpos % PIPEBUFSIZ];
  80267c:	89 c2                	mov    %eax,%edx
  80267e:	c1 fa 1f             	sar    $0x1f,%edx
  802681:	c1 ea 1b             	shr    $0x1b,%edx
  802684:	01 d0                	add    %edx,%eax
  802686:	83 e0 1f             	and    $0x1f,%eax
  802689:	29 d0                	sub    %edx,%eax
  80268b:	0f b6 44 03 08       	movzbl 0x8(%ebx,%eax,1),%eax
  802690:	8b 55 0c             	mov    0xc(%ebp),%edx
  802693:	88 04 32             	mov    %al,(%edx,%esi,1)
		p->p_rpos++;
  802696:	83 03 01             	addl   $0x1,(%ebx)
	if (debug)
		cprintf("[%08x] devpipe_read %08x %d rpos %d wpos %d\n",
			env->env_id, vpt[VPN(p)], n, p->p_rpos, p->p_wpos);

	buf = vbuf;
	for (i = 0; i < n; i++) {
  802699:	83 c6 01             	add    $0x1,%esi
  80269c:	39 75 10             	cmp    %esi,0x10(%ebp)
  80269f:	76 16                	jbe    8026b7 <devpipe_read+0x89>
		while (p->p_rpos == p->p_wpos) {
  8026a1:	8b 03                	mov    (%ebx),%eax
  8026a3:	3b 43 04             	cmp    0x4(%ebx),%eax
  8026a6:	75 d4                	jne    80267c <devpipe_read+0x4e>
			// pipe is empty
			// if we got any data, return it
			if (i > 0)
  8026a8:	85 f6                	test   %esi,%esi
  8026aa:	75 ab                	jne    802657 <devpipe_read+0x29>
  8026ac:	8d 74 26 00          	lea    0x0(%esi,%eiz,1),%esi
  8026b0:	eb a9                	jmp    80265b <devpipe_read+0x2d>
  8026b2:	be 00 00 00 00       	mov    $0x0,%esi
		// there's a byte.  take it.
		// wait to increment rpos until the byte is taken!
		buf[i] = p->p_buf[p->p_rpos % PIPEBUFSIZ];
		p->p_rpos++;
	}
	return i;
  8026b7:	89 f0                	mov    %esi,%eax
}
  8026b9:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  8026bc:	8b 75 f8             	mov    -0x8(%ebp),%esi
  8026bf:	8b 7d fc             	mov    -0x4(%ebp),%edi
  8026c2:	89 ec                	mov    %ebp,%esp
  8026c4:	5d                   	pop    %ebp
  8026c5:	c3                   	ret    

008026c6 <pipeisclosed>:
	}
}

int
pipeisclosed(int fdnum)
{
  8026c6:	55                   	push   %ebp
  8026c7:	89 e5                	mov    %esp,%ebp
  8026c9:	83 ec 28             	sub    $0x28,%esp
	struct Fd *fd;
	struct Pipe *p;
	int r;

	if ((r = fd_lookup(fdnum, &fd)) < 0)
  8026cc:	8d 45 f4             	lea    -0xc(%ebp),%eax
  8026cf:	89 44 24 04          	mov    %eax,0x4(%esp)
  8026d3:	8b 45 08             	mov    0x8(%ebp),%eax
  8026d6:	89 04 24             	mov    %eax,(%esp)
  8026d9:	e8 5f f0 ff ff       	call   80173d <fd_lookup>
  8026de:	85 c0                	test   %eax,%eax
  8026e0:	78 15                	js     8026f7 <pipeisclosed+0x31>
		return r;
	p = (struct Pipe*) fd2data(fd);
  8026e2:	8b 45 f4             	mov    -0xc(%ebp),%eax
  8026e5:	89 04 24             	mov    %eax,(%esp)
  8026e8:	e8 c3 ef ff ff       	call   8016b0 <fd2data>
	return _pipeisclosed(fd, p);
  8026ed:	89 c2                	mov    %eax,%edx
  8026ef:	8b 45 f4             	mov    -0xc(%ebp),%eax
  8026f2:	e8 3b fe ff ff       	call   802532 <_pipeisclosed>
}
  8026f7:	c9                   	leave  
  8026f8:	c3                   	ret    

008026f9 <pipe>:
	uint8_t p_buf[PIPEBUFSIZ];	// data buffer
};

int
pipe(int pfd[2])
{
  8026f9:	55                   	push   %ebp
  8026fa:	89 e5                	mov    %esp,%ebp
  8026fc:	83 ec 48             	sub    $0x48,%esp
  8026ff:	89 5d f4             	mov    %ebx,-0xc(%ebp)
  802702:	89 75 f8             	mov    %esi,-0x8(%ebp)
  802705:	89 7d fc             	mov    %edi,-0x4(%ebp)
  802708:	8b 7d 08             	mov    0x8(%ebp),%edi
	int r;
	struct Fd *fd0, *fd1;
	void *va;

	// allocate the file descriptor table entries
	if ((r = fd_alloc(&fd0)) < 0
  80270b:	8d 45 e4             	lea    -0x1c(%ebp),%eax
  80270e:	89 04 24             	mov    %eax,(%esp)
  802711:	e8 b5 ef ff ff       	call   8016cb <fd_alloc>
  802716:	89 c3                	mov    %eax,%ebx
  802718:	85 c0                	test   %eax,%eax
  80271a:	0f 88 42 01 00 00    	js     802862 <pipe+0x169>
	    || (r = sys_page_alloc(0, fd0, PTE_P|PTE_W|PTE_U|PTE_SHARE)) < 0)
  802720:	c7 44 24 08 07 04 00 	movl   $0x407,0x8(%esp)
  802727:	00 
  802728:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  80272b:	89 44 24 04          	mov    %eax,0x4(%esp)
  80272f:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  802736:	e8 6b e9 ff ff       	call   8010a6 <sys_page_alloc>
  80273b:	89 c3                	mov    %eax,%ebx
	int r;
	struct Fd *fd0, *fd1;
	void *va;

	// allocate the file descriptor table entries
	if ((r = fd_alloc(&fd0)) < 0
  80273d:	85 c0                	test   %eax,%eax
  80273f:	0f 88 1d 01 00 00    	js     802862 <pipe+0x169>
	    || (r = sys_page_alloc(0, fd0, PTE_P|PTE_W|PTE_U|PTE_SHARE)) < 0)
		goto err;

	if ((r = fd_alloc(&fd1)) < 0
  802745:	8d 45 e0             	lea    -0x20(%ebp),%eax
  802748:	89 04 24             	mov    %eax,(%esp)
  80274b:	e8 7b ef ff ff       	call   8016cb <fd_alloc>
  802750:	89 c3                	mov    %eax,%ebx
  802752:	85 c0                	test   %eax,%eax
  802754:	0f 88 f5 00 00 00    	js     80284f <pipe+0x156>
	    || (r = sys_page_alloc(0, fd1, PTE_P|PTE_W|PTE_U|PTE_SHARE)) < 0)
  80275a:	c7 44 24 08 07 04 00 	movl   $0x407,0x8(%esp)
  802761:	00 
  802762:	8b 45 e0             	mov    -0x20(%ebp),%eax
  802765:	89 44 24 04          	mov    %eax,0x4(%esp)
  802769:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  802770:	e8 31 e9 ff ff       	call   8010a6 <sys_page_alloc>
  802775:	89 c3                	mov    %eax,%ebx
	// allocate the file descriptor table entries
	if ((r = fd_alloc(&fd0)) < 0
	    || (r = sys_page_alloc(0, fd0, PTE_P|PTE_W|PTE_U|PTE_SHARE)) < 0)
		goto err;

	if ((r = fd_alloc(&fd1)) < 0
  802777:	85 c0                	test   %eax,%eax
  802779:	0f 88 d0 00 00 00    	js     80284f <pipe+0x156>
	    || (r = sys_page_alloc(0, fd1, PTE_P|PTE_W|PTE_U|PTE_SHARE)) < 0)
		goto err1;

	// allocate the pipe structure as first data page in both
	va = fd2data(fd0);
  80277f:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  802782:	89 04 24             	mov    %eax,(%esp)
  802785:	e8 26 ef ff ff       	call   8016b0 <fd2data>
  80278a:	89 c6                	mov    %eax,%esi
	if ((r = sys_page_alloc(0, va, PTE_P|PTE_W|PTE_U|PTE_SHARE)) < 0)
  80278c:	c7 44 24 08 07 04 00 	movl   $0x407,0x8(%esp)
  802793:	00 
  802794:	89 44 24 04          	mov    %eax,0x4(%esp)
  802798:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  80279f:	e8 02 e9 ff ff       	call   8010a6 <sys_page_alloc>
  8027a4:	89 c3                	mov    %eax,%ebx
  8027a6:	85 c0                	test   %eax,%eax
  8027a8:	0f 88 8e 00 00 00    	js     80283c <pipe+0x143>
		goto err2;
	if ((r = sys_page_map(0, va, 0, fd2data(fd1), PTE_P|PTE_W|PTE_U|PTE_SHARE)) < 0)
  8027ae:	8b 45 e0             	mov    -0x20(%ebp),%eax
  8027b1:	89 04 24             	mov    %eax,(%esp)
  8027b4:	e8 f7 ee ff ff       	call   8016b0 <fd2data>
  8027b9:	c7 44 24 10 07 04 00 	movl   $0x407,0x10(%esp)
  8027c0:	00 
  8027c1:	89 44 24 0c          	mov    %eax,0xc(%esp)
  8027c5:	c7 44 24 08 00 00 00 	movl   $0x0,0x8(%esp)
  8027cc:	00 
  8027cd:	89 74 24 04          	mov    %esi,0x4(%esp)
  8027d1:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  8027d8:	e8 6b e8 ff ff       	call   801048 <sys_page_map>
  8027dd:	89 c3                	mov    %eax,%ebx
  8027df:	85 c0                	test   %eax,%eax
  8027e1:	78 49                	js     80282c <pipe+0x133>
		goto err3;

	// set up fd structures
	fd0->fd_dev_id = devpipe.dev_id;
  8027e3:	b8 3c 70 80 00       	mov    $0x80703c,%eax
  8027e8:	8b 08                	mov    (%eax),%ecx
  8027ea:	8b 55 e4             	mov    -0x1c(%ebp),%edx
  8027ed:	89 0a                	mov    %ecx,(%edx)
	fd0->fd_omode = O_RDONLY;
  8027ef:	8b 55 e4             	mov    -0x1c(%ebp),%edx
  8027f2:	c7 42 08 00 00 00 00 	movl   $0x0,0x8(%edx)

	fd1->fd_dev_id = devpipe.dev_id;
  8027f9:	8b 10                	mov    (%eax),%edx
  8027fb:	8b 45 e0             	mov    -0x20(%ebp),%eax
  8027fe:	89 10                	mov    %edx,(%eax)
	fd1->fd_omode = O_WRONLY;
  802800:	8b 45 e0             	mov    -0x20(%ebp),%eax
  802803:	c7 40 08 01 00 00 00 	movl   $0x1,0x8(%eax)

	if (debug)
		cprintf("[%08x] pipecreate %08x\n", env->env_id, vpt[VPN(va)]);

	pfd[0] = fd2num(fd0);
  80280a:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  80280d:	89 04 24             	mov    %eax,(%esp)
  802810:	e8 8b ee ff ff       	call   8016a0 <fd2num>
  802815:	89 07                	mov    %eax,(%edi)
	pfd[1] = fd2num(fd1);
  802817:	8b 45 e0             	mov    -0x20(%ebp),%eax
  80281a:	89 04 24             	mov    %eax,(%esp)
  80281d:	e8 7e ee ff ff       	call   8016a0 <fd2num>
  802822:	89 47 04             	mov    %eax,0x4(%edi)
  802825:	bb 00 00 00 00       	mov    $0x0,%ebx
	return 0;
  80282a:	eb 36                	jmp    802862 <pipe+0x169>

    err3:
	sys_page_unmap(0, va);
  80282c:	89 74 24 04          	mov    %esi,0x4(%esp)
  802830:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  802837:	e8 ae e7 ff ff       	call   800fea <sys_page_unmap>
    err2:
	sys_page_unmap(0, fd1);
  80283c:	8b 45 e0             	mov    -0x20(%ebp),%eax
  80283f:	89 44 24 04          	mov    %eax,0x4(%esp)
  802843:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  80284a:	e8 9b e7 ff ff       	call   800fea <sys_page_unmap>
    err1:
	sys_page_unmap(0, fd0);
  80284f:	8b 45 e4             	mov    -0x1c(%ebp),%eax
  802852:	89 44 24 04          	mov    %eax,0x4(%esp)
  802856:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  80285d:	e8 88 e7 ff ff       	call   800fea <sys_page_unmap>
    err:
	return r;
}
  802862:	89 d8                	mov    %ebx,%eax
  802864:	8b 5d f4             	mov    -0xc(%ebp),%ebx
  802867:	8b 75 f8             	mov    -0x8(%ebp),%esi
  80286a:	8b 7d fc             	mov    -0x4(%ebp),%edi
  80286d:	89 ec                	mov    %ebp,%esp
  80286f:	5d                   	pop    %ebp
  802870:	c3                   	ret    
	...

00802880 <devcons_close>:
	return tot;
}

static int
devcons_close(struct Fd *fd)
{
  802880:	55                   	push   %ebp
  802881:	89 e5                	mov    %esp,%ebp
	USED(fd);

	return 0;
}
  802883:	b8 00 00 00 00       	mov    $0x0,%eax
  802888:	5d                   	pop    %ebp
  802889:	c3                   	ret    

0080288a <devcons_stat>:

static int
devcons_stat(struct Fd *fd, struct Stat *stat)
{
  80288a:	55                   	push   %ebp
  80288b:	89 e5                	mov    %esp,%ebp
  80288d:	83 ec 18             	sub    $0x18,%esp
	strcpy(stat->st_name, "<cons>");
  802890:	c7 44 24 04 05 34 80 	movl   $0x803405,0x4(%esp)
  802897:	00 
  802898:	8b 45 0c             	mov    0xc(%ebp),%eax
  80289b:	89 04 24             	mov    %eax,(%esp)
  80289e:	e8 a7 e0 ff ff       	call   80094a <strcpy>
	return 0;
}
  8028a3:	b8 00 00 00 00       	mov    $0x0,%eax
  8028a8:	c9                   	leave  
  8028a9:	c3                   	ret    

008028aa <devcons_write>:
	return 1;
}

static ssize_t
devcons_write(struct Fd *fd, const void *vbuf, size_t n)
{
  8028aa:	55                   	push   %ebp
  8028ab:	89 e5                	mov    %esp,%ebp
  8028ad:	57                   	push   %edi
  8028ae:	56                   	push   %esi
  8028af:	53                   	push   %ebx
  8028b0:	81 ec 9c 00 00 00    	sub    $0x9c,%esp
	int tot, m;
	char buf[128];

	// mistake: have to nul-terminate arg to sys_cputs, 
	// so we have to copy vbuf into buf in chunks and nul-terminate.
	for (tot = 0; tot < n; tot += m) {
  8028b6:	b8 00 00 00 00       	mov    $0x0,%eax
  8028bb:	be 00 00 00 00       	mov    $0x0,%esi
  8028c0:	83 7d 10 00          	cmpl   $0x0,0x10(%ebp)
  8028c4:	74 41                	je     802907 <devcons_write+0x5d>
		m = n - tot;
		if (m > sizeof(buf) - 1)
			m = sizeof(buf) - 1;
		memmove(buf, (char*)vbuf + tot, m);
  8028c6:	8d bd 68 ff ff ff    	lea    -0x98(%ebp),%edi
	char buf[128];

	// mistake: have to nul-terminate arg to sys_cputs, 
	// so we have to copy vbuf into buf in chunks and nul-terminate.
	for (tot = 0; tot < n; tot += m) {
		m = n - tot;
  8028cc:	8b 5d 10             	mov    0x10(%ebp),%ebx
  8028cf:	29 c3                	sub    %eax,%ebx
		if (m > sizeof(buf) - 1)
  8028d1:	81 fb 80 00 00 00    	cmp    $0x80,%ebx
  8028d7:	ba 7f 00 00 00       	mov    $0x7f,%edx
  8028dc:	0f 43 da             	cmovae %edx,%ebx
			m = sizeof(buf) - 1;
		memmove(buf, (char*)vbuf + tot, m);
  8028df:	89 5c 24 08          	mov    %ebx,0x8(%esp)
  8028e3:	03 45 0c             	add    0xc(%ebp),%eax
  8028e6:	89 44 24 04          	mov    %eax,0x4(%esp)
  8028ea:	89 3c 24             	mov    %edi,(%esp)
  8028ed:	e8 13 e2 ff ff       	call   800b05 <memmove>
		sys_cputs(buf, m);
  8028f2:	89 5c 24 04          	mov    %ebx,0x4(%esp)
  8028f6:	89 3c 24             	mov    %edi,(%esp)
  8028f9:	e8 42 e4 ff ff       	call   800d40 <sys_cputs>
	int tot, m;
	char buf[128];

	// mistake: have to nul-terminate arg to sys_cputs, 
	// so we have to copy vbuf into buf in chunks and nul-terminate.
	for (tot = 0; tot < n; tot += m) {
  8028fe:	01 de                	add    %ebx,%esi
  802900:	89 f0                	mov    %esi,%eax
  802902:	3b 75 10             	cmp    0x10(%ebp),%esi
  802905:	72 c5                	jb     8028cc <devcons_write+0x22>
			m = sizeof(buf) - 1;
		memmove(buf, (char*)vbuf + tot, m);
		sys_cputs(buf, m);
	}
	return tot;
}
  802907:	89 f0                	mov    %esi,%eax
  802909:	81 c4 9c 00 00 00    	add    $0x9c,%esp
  80290f:	5b                   	pop    %ebx
  802910:	5e                   	pop    %esi
  802911:	5f                   	pop    %edi
  802912:	5d                   	pop    %ebp
  802913:	c3                   	ret    

00802914 <cputchar>:
#include <inc/string.h>
#include <inc/lib.h>

void
cputchar(int ch)
{
  802914:	55                   	push   %ebp
  802915:	89 e5                	mov    %esp,%ebp
  802917:	83 ec 28             	sub    $0x28,%esp
	char c = ch;
  80291a:	8b 45 08             	mov    0x8(%ebp),%eax
  80291d:	88 45 f7             	mov    %al,-0x9(%ebp)

	// Unlike standard Unix's putchar,
	// the cputchar function _always_ outputs to the system console.
	sys_cputs(&c, 1);
  802920:	c7 44 24 04 01 00 00 	movl   $0x1,0x4(%esp)
  802927:	00 
  802928:	8d 45 f7             	lea    -0x9(%ebp),%eax
  80292b:	89 04 24             	mov    %eax,(%esp)
  80292e:	e8 0d e4 ff ff       	call   800d40 <sys_cputs>
}
  802933:	c9                   	leave  
  802934:	c3                   	ret    

00802935 <devcons_read>:
	return fd2num(fd);
}

static ssize_t
devcons_read(struct Fd *fd, void *vbuf, size_t n)
{
  802935:	55                   	push   %ebp
  802936:	89 e5                	mov    %esp,%ebp
  802938:	83 ec 08             	sub    $0x8,%esp
	int c;

	if (n == 0)
  80293b:	83 7d 10 00          	cmpl   $0x0,0x10(%ebp)
  80293f:	75 07                	jne    802948 <devcons_read+0x13>
  802941:	eb 2d                	jmp    802970 <devcons_read+0x3b>
		return 0;
	while ((c = sys_cgetc()) == 0)
		sys_yield();
  802943:	e8 bd e7 ff ff       	call   801105 <sys_yield>
{
	int c;

	if (n == 0)
		return 0;
	while ((c = sys_cgetc()) == 0)
  802948:	90                   	nop
  802949:	8d b4 26 00 00 00 00 	lea    0x0(%esi,%eiz,1),%esi
  802950:	e8 b7 e3 ff ff       	call   800d0c <sys_cgetc>
  802955:	85 c0                	test   %eax,%eax
  802957:	74 ea                	je     802943 <devcons_read+0xe>
  802959:	89 c2                	mov    %eax,%edx
		sys_yield();
	if (c < 0)
  80295b:	85 c0                	test   %eax,%eax
  80295d:	78 16                	js     802975 <devcons_read+0x40>
		return c;
	if (c == 0x04)	// ctl-d is eof
  80295f:	83 f8 04             	cmp    $0x4,%eax
  802962:	74 0c                	je     802970 <devcons_read+0x3b>
		return 0;
	*(char*)vbuf = c;
  802964:	8b 45 0c             	mov    0xc(%ebp),%eax
  802967:	88 10                	mov    %dl,(%eax)
  802969:	b8 01 00 00 00       	mov    $0x1,%eax
	return 1;
  80296e:	eb 05                	jmp    802975 <devcons_read+0x40>
  802970:	b8 00 00 00 00       	mov    $0x0,%eax
}
  802975:	c9                   	leave  
  802976:	c3                   	ret    

00802977 <opencons>:
	return fd->fd_dev_id == devcons.dev_id;
}

int
opencons(void)
{
  802977:	55                   	push   %ebp
  802978:	89 e5                	mov    %esp,%ebp
  80297a:	83 ec 28             	sub    $0x28,%esp
	int r;
	struct Fd* fd;

	if ((r = fd_alloc(&fd)) < 0)
  80297d:	8d 45 f4             	lea    -0xc(%ebp),%eax
  802980:	89 04 24             	mov    %eax,(%esp)
  802983:	e8 43 ed ff ff       	call   8016cb <fd_alloc>
  802988:	85 c0                	test   %eax,%eax
  80298a:	78 3f                	js     8029cb <opencons+0x54>
		return r;
	if ((r = sys_page_alloc(0, fd, PTE_P|PTE_U|PTE_W|PTE_SHARE)) < 0)
  80298c:	c7 44 24 08 07 04 00 	movl   $0x407,0x8(%esp)
  802993:	00 
  802994:	8b 45 f4             	mov    -0xc(%ebp),%eax
  802997:	89 44 24 04          	mov    %eax,0x4(%esp)
  80299b:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  8029a2:	e8 ff e6 ff ff       	call   8010a6 <sys_page_alloc>
  8029a7:	85 c0                	test   %eax,%eax
  8029a9:	78 20                	js     8029cb <opencons+0x54>
		return r;
	fd->fd_dev_id = devcons.dev_id;
  8029ab:	8b 15 58 70 80 00    	mov    0x807058,%edx
  8029b1:	8b 45 f4             	mov    -0xc(%ebp),%eax
  8029b4:	89 10                	mov    %edx,(%eax)
	fd->fd_omode = O_RDWR;
  8029b6:	8b 45 f4             	mov    -0xc(%ebp),%eax
  8029b9:	c7 40 08 02 00 00 00 	movl   $0x2,0x8(%eax)
	return fd2num(fd);
  8029c0:	8b 45 f4             	mov    -0xc(%ebp),%eax
  8029c3:	89 04 24             	mov    %eax,(%esp)
  8029c6:	e8 d5 ec ff ff       	call   8016a0 <fd2num>
}
  8029cb:	c9                   	leave  
  8029cc:	c3                   	ret    

008029cd <iscons>:
	.dev_stat =	devcons_stat
};

int
iscons(int fdnum)
{
  8029cd:	55                   	push   %ebp
  8029ce:	89 e5                	mov    %esp,%ebp
  8029d0:	83 ec 28             	sub    $0x28,%esp
	int r;
	struct Fd *fd;

	if ((r = fd_lookup(fdnum, &fd)) < 0)
  8029d3:	8d 45 f4             	lea    -0xc(%ebp),%eax
  8029d6:	89 44 24 04          	mov    %eax,0x4(%esp)
  8029da:	8b 45 08             	mov    0x8(%ebp),%eax
  8029dd:	89 04 24             	mov    %eax,(%esp)
  8029e0:	e8 58 ed ff ff       	call   80173d <fd_lookup>
  8029e5:	85 c0                	test   %eax,%eax
  8029e7:	78 11                	js     8029fa <iscons+0x2d>
		return r;
	return fd->fd_dev_id == devcons.dev_id;
  8029e9:	8b 45 f4             	mov    -0xc(%ebp),%eax
  8029ec:	8b 00                	mov    (%eax),%eax
  8029ee:	3b 05 58 70 80 00    	cmp    0x807058,%eax
  8029f4:	0f 94 c0             	sete   %al
  8029f7:	0f b6 c0             	movzbl %al,%eax
}
  8029fa:	c9                   	leave  
  8029fb:	c3                   	ret    

008029fc <getchar>:
	sys_cputs(&c, 1);
}

int
getchar(void)
{
  8029fc:	55                   	push   %ebp
  8029fd:	89 e5                	mov    %esp,%ebp
  8029ff:	83 ec 28             	sub    $0x28,%esp
	int r;

	// JOS does, however, support standard _input_ redirection,
	// allowing the user to redirect script files to the shell and such.
	// getchar() reads a character from file descriptor 0.
	r = read(0, &c, 1);
  802a02:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
  802a09:	00 
  802a0a:	8d 45 f7             	lea    -0x9(%ebp),%eax
  802a0d:	89 44 24 04          	mov    %eax,0x4(%esp)
  802a11:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  802a18:	e8 86 ef ff ff       	call   8019a3 <read>
	if (r < 0)
  802a1d:	85 c0                	test   %eax,%eax
  802a1f:	78 0f                	js     802a30 <getchar+0x34>
		return r;
	if (r < 1)
  802a21:	85 c0                	test   %eax,%eax
  802a23:	7f 07                	jg     802a2c <getchar+0x30>
  802a25:	b8 f8 ff ff ff       	mov    $0xfffffff8,%eax
  802a2a:	eb 04                	jmp    802a30 <getchar+0x34>
		return -E_EOF;
	return c;
  802a2c:	0f b6 45 f7          	movzbl -0x9(%ebp),%eax
}
  802a30:	c9                   	leave  
  802a31:	c3                   	ret    
	...

00802a34 <set_pgfault_handler>:
// at UXSTACKTOP), and tell the kernel to call the assembly-language
// _pgfault_upcall routine when a page fault occurs.
//
void
set_pgfault_handler(void (*handler)(struct UTrapframe *utf))
{
  802a34:	55                   	push   %ebp
  802a35:	89 e5                	mov    %esp,%ebp
  802a37:	83 ec 18             	sub    $0x18,%esp
	int r;

	if (_pgfault_handler == NULL) {
  802a3a:	83 3d 7c 70 80 00 00 	cmpl   $0x0,0x80707c
  802a41:	75 55                	jne    802a98 <set_pgfault_handler+0x64>
		// First time through!
		// LAB 4: Your code here.
        if (sys_page_alloc(sys_getenvid(), (void *)(UXSTACKTOP-PGSIZE), PTE_P|PTE_U|PTE_W))
  802a43:	e8 f1 e6 ff ff       	call   801139 <sys_getenvid>
  802a48:	c7 44 24 08 07 00 00 	movl   $0x7,0x8(%esp)
  802a4f:	00 
  802a50:	c7 44 24 04 00 f0 bf 	movl   $0xeebff000,0x4(%esp)
  802a57:	ee 
  802a58:	89 04 24             	mov    %eax,(%esp)
  802a5b:	e8 46 e6 ff ff       	call   8010a6 <sys_page_alloc>
  802a60:	85 c0                	test   %eax,%eax
  802a62:	74 1c                	je     802a80 <set_pgfault_handler+0x4c>
		    panic("set_pgfault_handler not implemented");
  802a64:	c7 44 24 08 14 34 80 	movl   $0x803414,0x8(%esp)
  802a6b:	00 
  802a6c:	c7 44 24 04 21 00 00 	movl   $0x21,0x4(%esp)
  802a73:	00 
  802a74:	c7 04 24 38 34 80 00 	movl   $0x803438,(%esp)
  802a7b:	e8 30 d7 ff ff       	call   8001b0 <_panic>
        sys_env_set_pgfault_upcall(env->env_id, _pgfault_upcall);
  802a80:	a1 74 70 80 00       	mov    0x807074,%eax
  802a85:	8b 40 4c             	mov    0x4c(%eax),%eax
  802a88:	c7 44 24 04 a4 2a 80 	movl   $0x802aa4,0x4(%esp)
  802a8f:	00 
  802a90:	89 04 24             	mov    %eax,(%esp)
  802a93:	e8 38 e4 ff ff       	call   800ed0 <sys_env_set_pgfault_upcall>
	}

	// Save handler pointer for assembly to call.
	_pgfault_handler = handler;
  802a98:	8b 45 08             	mov    0x8(%ebp),%eax
  802a9b:	a3 7c 70 80 00       	mov    %eax,0x80707c
}
  802aa0:	c9                   	leave  
  802aa1:	c3                   	ret    
	...

00802aa4 <_pgfault_upcall>:

.text
.globl _pgfault_upcall
_pgfault_upcall:
	// Call the C page fault handler.
	pushl %esp			// function argument: pointer to UTF
  802aa4:	54                   	push   %esp
	movl _pgfault_handler, %eax
  802aa5:	a1 7c 70 80 00       	mov    0x80707c,%eax
	call *%eax
  802aaa:	ff d0                	call   *%eax
	addl $4, %esp			// pop function argument
  802aac:	83 c4 04             	add    $0x4,%esp
	// may find that you have to rearrange your code in non-obvious
	// ways as registers become unavailable as scratch space.
	//
	// LAB 4: Your code here.

    subl $4, 48(%esp)
  802aaf:	83 6c 24 30 04       	subl   $0x4,0x30(%esp)
    movl 48(%esp), %eax
  802ab4:	8b 44 24 30          	mov    0x30(%esp),%eax
    movl 40(%esp), %ebx
  802ab8:	8b 5c 24 28          	mov    0x28(%esp),%ebx
    movl %ebx, (%eax)
  802abc:	89 18                	mov    %ebx,(%eax)
    
	// Restore the trap-time registers.  After you do this, you
	// can no longer modify any general-purpose registers.
	// LAB 4: Your code here.
    addl $8, %esp
  802abe:	83 c4 08             	add    $0x8,%esp
    popal
  802ac1:	61                   	popa   
   
	// Restore eflags from the stack.  After you do this, you can
	// no longer use arithmetic operations or anything else that
	// modifies eflags.
	// LAB 4: Your code here.
    pushl 4(%esp)
  802ac2:	ff 74 24 04          	pushl  0x4(%esp)
    popf
  802ac6:	9d                   	popf   

	// Switch back to the adjusted trap-time stack.
	// LAB 4: Your code here.
    movl 8(%esp), %esp
  802ac7:	8b 64 24 08          	mov    0x8(%esp),%esp

	// Return to re-execute the instruction that faulted.
	// LAB 4: Your code here.
    ret
  802acb:	c3                   	ret    

00802acc <pageref>:
#include <inc/lib.h>

int
pageref(void *v)
{
  802acc:	55                   	push   %ebp
  802acd:	89 e5                	mov    %esp,%ebp
	pte_t pte;

	if (!(vpd[PDX(v)] & PTE_P))
  802acf:	8b 45 08             	mov    0x8(%ebp),%eax
  802ad2:	89 c2                	mov    %eax,%edx
  802ad4:	c1 ea 16             	shr    $0x16,%edx
  802ad7:	8b 14 95 00 d0 7b ef 	mov    -0x10843000(,%edx,4),%edx
  802ade:	f6 c2 01             	test   $0x1,%dl
  802ae1:	74 26                	je     802b09 <pageref+0x3d>
		return 0;
	pte = vpt[VPN(v)];
  802ae3:	c1 e8 0c             	shr    $0xc,%eax
  802ae6:	8b 04 85 00 00 40 ef 	mov    -0x10c00000(,%eax,4),%eax
	if (!(pte & PTE_P))
  802aed:	a8 01                	test   $0x1,%al
  802aef:	74 18                	je     802b09 <pageref+0x3d>
		return 0;
	return pages[PPN(pte)].pp_ref;
  802af1:	c1 e8 0c             	shr    $0xc,%eax
  802af4:	8d 14 40             	lea    (%eax,%eax,2),%edx
  802af7:	c1 e2 02             	shl    $0x2,%edx
  802afa:	b8 00 00 00 ef       	mov    $0xef000000,%eax
  802aff:	0f b7 44 02 08       	movzwl 0x8(%edx,%eax,1),%eax
  802b04:	0f b7 c0             	movzwl %ax,%eax
  802b07:	eb 05                	jmp    802b0e <pageref+0x42>
  802b09:	b8 00 00 00 00       	mov    $0x0,%eax
}
  802b0e:	5d                   	pop    %ebp
  802b0f:	c3                   	ret    

00802b10 <__udivdi3>:
  802b10:	55                   	push   %ebp
  802b11:	89 e5                	mov    %esp,%ebp
  802b13:	57                   	push   %edi
  802b14:	56                   	push   %esi
  802b15:	83 ec 10             	sub    $0x10,%esp
  802b18:	8b 45 14             	mov    0x14(%ebp),%eax
  802b1b:	8b 55 08             	mov    0x8(%ebp),%edx
  802b1e:	8b 75 10             	mov    0x10(%ebp),%esi
  802b21:	8b 7d 0c             	mov    0xc(%ebp),%edi
  802b24:	85 c0                	test   %eax,%eax
  802b26:	89 55 f0             	mov    %edx,-0x10(%ebp)
  802b29:	75 35                	jne    802b60 <__udivdi3+0x50>
  802b2b:	39 fe                	cmp    %edi,%esi
  802b2d:	77 61                	ja     802b90 <__udivdi3+0x80>
  802b2f:	85 f6                	test   %esi,%esi
  802b31:	75 0b                	jne    802b3e <__udivdi3+0x2e>
  802b33:	b8 01 00 00 00       	mov    $0x1,%eax
  802b38:	31 d2                	xor    %edx,%edx
  802b3a:	f7 f6                	div    %esi
  802b3c:	89 c6                	mov    %eax,%esi
  802b3e:	8b 4d f0             	mov    -0x10(%ebp),%ecx
  802b41:	31 d2                	xor    %edx,%edx
  802b43:	89 f8                	mov    %edi,%eax
  802b45:	f7 f6                	div    %esi
  802b47:	89 c7                	mov    %eax,%edi
  802b49:	89 c8                	mov    %ecx,%eax
  802b4b:	f7 f6                	div    %esi
  802b4d:	89 c1                	mov    %eax,%ecx
  802b4f:	89 fa                	mov    %edi,%edx
  802b51:	89 c8                	mov    %ecx,%eax
  802b53:	83 c4 10             	add    $0x10,%esp
  802b56:	5e                   	pop    %esi
  802b57:	5f                   	pop    %edi
  802b58:	5d                   	pop    %ebp
  802b59:	c3                   	ret    
  802b5a:	8d b6 00 00 00 00    	lea    0x0(%esi),%esi
  802b60:	39 f8                	cmp    %edi,%eax
  802b62:	77 1c                	ja     802b80 <__udivdi3+0x70>
  802b64:	0f bd d0             	bsr    %eax,%edx
  802b67:	83 f2 1f             	xor    $0x1f,%edx
  802b6a:	89 55 f4             	mov    %edx,-0xc(%ebp)
  802b6d:	75 39                	jne    802ba8 <__udivdi3+0x98>
  802b6f:	3b 75 f0             	cmp    -0x10(%ebp),%esi
  802b72:	0f 86 a0 00 00 00    	jbe    802c18 <__udivdi3+0x108>
  802b78:	39 f8                	cmp    %edi,%eax
  802b7a:	0f 82 98 00 00 00    	jb     802c18 <__udivdi3+0x108>
  802b80:	31 ff                	xor    %edi,%edi
  802b82:	31 c9                	xor    %ecx,%ecx
  802b84:	89 c8                	mov    %ecx,%eax
  802b86:	89 fa                	mov    %edi,%edx
  802b88:	83 c4 10             	add    $0x10,%esp
  802b8b:	5e                   	pop    %esi
  802b8c:	5f                   	pop    %edi
  802b8d:	5d                   	pop    %ebp
  802b8e:	c3                   	ret    
  802b8f:	90                   	nop
  802b90:	89 d1                	mov    %edx,%ecx
  802b92:	89 fa                	mov    %edi,%edx
  802b94:	89 c8                	mov    %ecx,%eax
  802b96:	31 ff                	xor    %edi,%edi
  802b98:	f7 f6                	div    %esi
  802b9a:	89 c1                	mov    %eax,%ecx
  802b9c:	89 fa                	mov    %edi,%edx
  802b9e:	89 c8                	mov    %ecx,%eax
  802ba0:	83 c4 10             	add    $0x10,%esp
  802ba3:	5e                   	pop    %esi
  802ba4:	5f                   	pop    %edi
  802ba5:	5d                   	pop    %ebp
  802ba6:	c3                   	ret    
  802ba7:	90                   	nop
  802ba8:	0f b6 4d f4          	movzbl -0xc(%ebp),%ecx
  802bac:	89 f2                	mov    %esi,%edx
  802bae:	d3 e0                	shl    %cl,%eax
  802bb0:	89 45 ec             	mov    %eax,-0x14(%ebp)
  802bb3:	b8 20 00 00 00       	mov    $0x20,%eax
  802bb8:	2b 45 f4             	sub    -0xc(%ebp),%eax
  802bbb:	89 c1                	mov    %eax,%ecx
  802bbd:	d3 ea                	shr    %cl,%edx
  802bbf:	0f b6 4d f4          	movzbl -0xc(%ebp),%ecx
  802bc3:	0b 55 ec             	or     -0x14(%ebp),%edx
  802bc6:	d3 e6                	shl    %cl,%esi
  802bc8:	89 c1                	mov    %eax,%ecx
  802bca:	89 75 e8             	mov    %esi,-0x18(%ebp)
  802bcd:	89 fe                	mov    %edi,%esi
  802bcf:	d3 ee                	shr    %cl,%esi
  802bd1:	0f b6 4d f4          	movzbl -0xc(%ebp),%ecx
  802bd5:	89 55 ec             	mov    %edx,-0x14(%ebp)
  802bd8:	8b 55 f0             	mov    -0x10(%ebp),%edx
  802bdb:	d3 e7                	shl    %cl,%edi
  802bdd:	89 c1                	mov    %eax,%ecx
  802bdf:	d3 ea                	shr    %cl,%edx
  802be1:	09 d7                	or     %edx,%edi
  802be3:	89 f2                	mov    %esi,%edx
  802be5:	89 f8                	mov    %edi,%eax
  802be7:	f7 75 ec             	divl   -0x14(%ebp)
  802bea:	89 d6                	mov    %edx,%esi
  802bec:	89 c7                	mov    %eax,%edi
  802bee:	f7 65 e8             	mull   -0x18(%ebp)
  802bf1:	39 d6                	cmp    %edx,%esi
  802bf3:	89 55 ec             	mov    %edx,-0x14(%ebp)
  802bf6:	72 30                	jb     802c28 <__udivdi3+0x118>
  802bf8:	8b 55 f0             	mov    -0x10(%ebp),%edx
  802bfb:	0f b6 4d f4          	movzbl -0xc(%ebp),%ecx
  802bff:	d3 e2                	shl    %cl,%edx
  802c01:	39 c2                	cmp    %eax,%edx
  802c03:	73 05                	jae    802c0a <__udivdi3+0xfa>
  802c05:	3b 75 ec             	cmp    -0x14(%ebp),%esi
  802c08:	74 1e                	je     802c28 <__udivdi3+0x118>
  802c0a:	89 f9                	mov    %edi,%ecx
  802c0c:	31 ff                	xor    %edi,%edi
  802c0e:	e9 71 ff ff ff       	jmp    802b84 <__udivdi3+0x74>
  802c13:	90                   	nop
  802c14:	8d 74 26 00          	lea    0x0(%esi,%eiz,1),%esi
  802c18:	31 ff                	xor    %edi,%edi
  802c1a:	b9 01 00 00 00       	mov    $0x1,%ecx
  802c1f:	e9 60 ff ff ff       	jmp    802b84 <__udivdi3+0x74>
  802c24:	8d 74 26 00          	lea    0x0(%esi,%eiz,1),%esi
  802c28:	8d 4f ff             	lea    -0x1(%edi),%ecx
  802c2b:	31 ff                	xor    %edi,%edi
  802c2d:	89 c8                	mov    %ecx,%eax
  802c2f:	89 fa                	mov    %edi,%edx
  802c31:	83 c4 10             	add    $0x10,%esp
  802c34:	5e                   	pop    %esi
  802c35:	5f                   	pop    %edi
  802c36:	5d                   	pop    %ebp
  802c37:	c3                   	ret    
	...

00802c40 <__umoddi3>:
  802c40:	55                   	push   %ebp
  802c41:	89 e5                	mov    %esp,%ebp
  802c43:	57                   	push   %edi
  802c44:	56                   	push   %esi
  802c45:	83 ec 20             	sub    $0x20,%esp
  802c48:	8b 55 14             	mov    0x14(%ebp),%edx
  802c4b:	8b 4d 08             	mov    0x8(%ebp),%ecx
  802c4e:	8b 7d 10             	mov    0x10(%ebp),%edi
  802c51:	8b 75 0c             	mov    0xc(%ebp),%esi
  802c54:	85 d2                	test   %edx,%edx
  802c56:	89 c8                	mov    %ecx,%eax
  802c58:	89 4d f4             	mov    %ecx,-0xc(%ebp)
  802c5b:	75 13                	jne    802c70 <__umoddi3+0x30>
  802c5d:	39 f7                	cmp    %esi,%edi
  802c5f:	76 3f                	jbe    802ca0 <__umoddi3+0x60>
  802c61:	89 f2                	mov    %esi,%edx
  802c63:	f7 f7                	div    %edi
  802c65:	89 d0                	mov    %edx,%eax
  802c67:	31 d2                	xor    %edx,%edx
  802c69:	83 c4 20             	add    $0x20,%esp
  802c6c:	5e                   	pop    %esi
  802c6d:	5f                   	pop    %edi
  802c6e:	5d                   	pop    %ebp
  802c6f:	c3                   	ret    
  802c70:	39 f2                	cmp    %esi,%edx
  802c72:	77 4c                	ja     802cc0 <__umoddi3+0x80>
  802c74:	0f bd ca             	bsr    %edx,%ecx
  802c77:	83 f1 1f             	xor    $0x1f,%ecx
  802c7a:	89 4d f0             	mov    %ecx,-0x10(%ebp)
  802c7d:	75 51                	jne    802cd0 <__umoddi3+0x90>
  802c7f:	3b 7d f4             	cmp    -0xc(%ebp),%edi
  802c82:	0f 87 e0 00 00 00    	ja     802d68 <__umoddi3+0x128>
  802c88:	8b 45 f4             	mov    -0xc(%ebp),%eax
  802c8b:	29 f8                	sub    %edi,%eax
  802c8d:	19 d6                	sbb    %edx,%esi
  802c8f:	89 45 f4             	mov    %eax,-0xc(%ebp)
  802c92:	8b 45 f4             	mov    -0xc(%ebp),%eax
  802c95:	89 f2                	mov    %esi,%edx
  802c97:	83 c4 20             	add    $0x20,%esp
  802c9a:	5e                   	pop    %esi
  802c9b:	5f                   	pop    %edi
  802c9c:	5d                   	pop    %ebp
  802c9d:	c3                   	ret    
  802c9e:	66 90                	xchg   %ax,%ax
  802ca0:	85 ff                	test   %edi,%edi
  802ca2:	75 0b                	jne    802caf <__umoddi3+0x6f>
  802ca4:	b8 01 00 00 00       	mov    $0x1,%eax
  802ca9:	31 d2                	xor    %edx,%edx
  802cab:	f7 f7                	div    %edi
  802cad:	89 c7                	mov    %eax,%edi
  802caf:	89 f0                	mov    %esi,%eax
  802cb1:	31 d2                	xor    %edx,%edx
  802cb3:	f7 f7                	div    %edi
  802cb5:	8b 45 f4             	mov    -0xc(%ebp),%eax
  802cb8:	f7 f7                	div    %edi
  802cba:	eb a9                	jmp    802c65 <__umoddi3+0x25>
  802cbc:	8d 74 26 00          	lea    0x0(%esi,%eiz,1),%esi
  802cc0:	89 c8                	mov    %ecx,%eax
  802cc2:	89 f2                	mov    %esi,%edx
  802cc4:	83 c4 20             	add    $0x20,%esp
  802cc7:	5e                   	pop    %esi
  802cc8:	5f                   	pop    %edi
  802cc9:	5d                   	pop    %ebp
  802cca:	c3                   	ret    
  802ccb:	90                   	nop
  802ccc:	8d 74 26 00          	lea    0x0(%esi,%eiz,1),%esi
  802cd0:	0f b6 4d f0          	movzbl -0x10(%ebp),%ecx
  802cd4:	d3 e2                	shl    %cl,%edx
  802cd6:	89 55 f4             	mov    %edx,-0xc(%ebp)
  802cd9:	ba 20 00 00 00       	mov    $0x20,%edx
  802cde:	2b 55 f0             	sub    -0x10(%ebp),%edx
  802ce1:	89 55 ec             	mov    %edx,-0x14(%ebp)
  802ce4:	0f b6 4d ec          	movzbl -0x14(%ebp),%ecx
  802ce8:	89 fa                	mov    %edi,%edx
  802cea:	d3 ea                	shr    %cl,%edx
  802cec:	0f b6 4d f0          	movzbl -0x10(%ebp),%ecx
  802cf0:	0b 55 f4             	or     -0xc(%ebp),%edx
  802cf3:	d3 e7                	shl    %cl,%edi
  802cf5:	0f b6 4d ec          	movzbl -0x14(%ebp),%ecx
  802cf9:	89 55 f4             	mov    %edx,-0xc(%ebp)
  802cfc:	89 f2                	mov    %esi,%edx
  802cfe:	89 7d e8             	mov    %edi,-0x18(%ebp)
  802d01:	89 c7                	mov    %eax,%edi
  802d03:	d3 ea                	shr    %cl,%edx
  802d05:	0f b6 4d f0          	movzbl -0x10(%ebp),%ecx
  802d09:	89 55 e4             	mov    %edx,-0x1c(%ebp)
  802d0c:	89 c2                	mov    %eax,%edx
  802d0e:	d3 e6                	shl    %cl,%esi
  802d10:	0f b6 4d ec          	movzbl -0x14(%ebp),%ecx
  802d14:	d3 ea                	shr    %cl,%edx
  802d16:	0f b6 4d f0          	movzbl -0x10(%ebp),%ecx
  802d1a:	09 d6                	or     %edx,%esi
  802d1c:	89 f0                	mov    %esi,%eax
  802d1e:	8b 75 e4             	mov    -0x1c(%ebp),%esi
  802d21:	d3 e7                	shl    %cl,%edi
  802d23:	89 f2                	mov    %esi,%edx
  802d25:	f7 75 f4             	divl   -0xc(%ebp)
  802d28:	89 d6                	mov    %edx,%esi
  802d2a:	f7 65 e8             	mull   -0x18(%ebp)
  802d2d:	39 d6                	cmp    %edx,%esi
  802d2f:	72 2b                	jb     802d5c <__umoddi3+0x11c>
  802d31:	39 c7                	cmp    %eax,%edi
  802d33:	72 23                	jb     802d58 <__umoddi3+0x118>
  802d35:	0f b6 4d f0          	movzbl -0x10(%ebp),%ecx
  802d39:	29 c7                	sub    %eax,%edi
  802d3b:	19 d6                	sbb    %edx,%esi
  802d3d:	89 f0                	mov    %esi,%eax
  802d3f:	89 f2                	mov    %esi,%edx
  802d41:	d3 ef                	shr    %cl,%edi
  802d43:	0f b6 4d ec          	movzbl -0x14(%ebp),%ecx
  802d47:	d3 e0                	shl    %cl,%eax
  802d49:	0f b6 4d f0          	movzbl -0x10(%ebp),%ecx
  802d4d:	09 f8                	or     %edi,%eax
  802d4f:	d3 ea                	shr    %cl,%edx
  802d51:	83 c4 20             	add    $0x20,%esp
  802d54:	5e                   	pop    %esi
  802d55:	5f                   	pop    %edi
  802d56:	5d                   	pop    %ebp
  802d57:	c3                   	ret    
  802d58:	39 d6                	cmp    %edx,%esi
  802d5a:	75 d9                	jne    802d35 <__umoddi3+0xf5>
  802d5c:	2b 45 e8             	sub    -0x18(%ebp),%eax
  802d5f:	1b 55 f4             	sbb    -0xc(%ebp),%edx
  802d62:	eb d1                	jmp    802d35 <__umoddi3+0xf5>
  802d64:	8d 74 26 00          	lea    0x0(%esi,%eiz,1),%esi
  802d68:	39 f2                	cmp    %esi,%edx
  802d6a:	0f 82 18 ff ff ff    	jb     802c88 <__umoddi3+0x48>
  802d70:	e9 1d ff ff ff       	jmp    802c92 <__umoddi3+0x52>
